/ Published in: ActionScript 3
There is a bug in AS3 where when you pause a looping mp3 the saved position gets messed up because the length extends with every looping instance.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
private var st:SoundTransform = new SoundTransform(0); private const max:int = int.MAX_VALUE; private var context:SoundLoaderContext = new SoundLoaderContext(2000, true); private var bkdSound:URLRequest = new URLRequest("background.mp3"); private var bkdS:Sound = new Sound(); private var pausePoint:Number = 0.00; private var paused:Boolean = false; function init():void{ bkdS.load(bkdSound, context); //START PLAYING THE SOUND bkdChannel = bkdS.play(0, max, st); } function pauseSound():void{ if(!paused){ //THIS PART IS THE KEY YOU NEED TO % INTO THE LENGTH OF THE SOUND pausePoint = bkdChannel.position % bkdS.length; bkdChannel.stop(); paused = true; }else{ //USE THIS TO RESUME// bkdChannel = bkdS.play(pausePoint, max, st ); paused = false; } }