I'm building an MP3 player from an xml list.
I've got everythign working okay except for the resume after pause button. my soundObject.start(offset) wont work unless I create a new sound object which has occurred so that multiple mp3s play at once.
Here is my code, I have basically nothing on my stage right now other then a list to select songs (which is fine), my next prev buttons which are okay.
The play pause is a movie clip with 4 keyframes that changes the text and weight of a font, no AS in the element itself other then a stop() frame
here is my code:
//!-- UTF8
/// Holding Variables
var Songs=Array();
var Current= -1;
var pos = 0;
var CurrentVolume=75;
var Sengine=new Sound();
Sengine.onSoundComplete = PlaySong;
Sengine.setVolume(75);
/// functions
function PlaySong()
{
if (Current == Songs.length - 1) Current = -1;
if (Current == -2) Current = Songs.length - 2;
Sengine.stop();
Sengine = new Sound();
Segine.setVolume(CurrentVolume);
Sengine.loadSound(Songs[++Current], true);
textbox.text=Current + 1;
}
SongXML = new XML();
SongXML.ignoreWhite = true;
SongXML.onLoad = function(success)
{
if(!success)
{
trace("Didnt load XML" + this.toString());
}
var cNodes=SongXML.firstChild.childNodes;
for (i=0; i<cNodes.length; i++)
{
Songs.push(cNodes[i].attributes.url);
listit.addItem(cNodes[i].attributes.title, i);
}
PlaySong();
}
SongXML.load("music.xml");
function nextprev(sum)
{
Current=Current + sum;
PlaySong();
}
/// interaction
listit.setChangeHandler("PickSong");
function PickSong()
{
Current=listit.getSelectedItem().data - 1;
PlaySong();
}
prev.onPress=function()
{
nextprev(-2);
}
next.onPress=function()
{
nextprev(0);
}
pauseclip.onRelease= function()
{
if (pauseclip._currentframe == 10)
{
pos = Sengine.position;
Sengine.stop();
pauseclip.gotoAndStop("playOver");
}
else if(pauseclip._currentframe == 30)
{
Sengine.start(pos / 1000);
pauseclip.gotoAndStop("pauseOver");
trace(pos)
}
}
pauseclip.onRollOver= function()
{
if (this._currentframe==20)
{
this.gotoAndStop("playOver");
}
if (this._currentframe == 1)
{
this.gotoAndPlay("pauseOver");
}
}
pauseclip.onRollOut = pause.onReleaseOutside= function()
{
if (this._currentframe==30)
{
this.gotoAndStop("play");
}
if (this._currentframe == 10)
{
this.gotoAndPlay("pause");
}
}
function AdjustSound(svalue)
{
Sengine.setVolume(svalue);
CurrentVolume(svalue);
}