In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Simple mp3 loop

I'm such a noob it hurts. How do I loop an mp3?
Get Adobe Flash player
by noobius 25 Dec 2010
/**
 * Copyright noobius ( http://wonderfl.net/user/noobius )
 * GNU General Public License, v3 ( http://www.gnu.org/licenses/quick-guide-gplv3.html )
 * Downloaded from: http://wonderfl.net/c/mEia
 */

/* I've been looking around other people's code and seen some awesome things, but I can't find an example of a looping mp3. I've found this code in a tutorial...
   Ideally the mp3 would loop with no gap.
   As you can tell, I have no idea where to begin. */

package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
                       
            
           // set up looping variables based on your
// mp3 encoding software
var leader:Number = 50;    // gap at the start of the mp3 (in ms)
var follower:Number = 50;  // gap at the end of the mp3 (in ms)
var placeToStop:Number;
// load mp3, start playing, and check the duration
var track:Sound = new Sound();
track.loadSound("http://www.someonelse.org/allurbase.mp3", false);   // false = non-streaming
track.onLoad = function(){
    track.start();
    placeToStop = track.duration - follower;
}
// run interval to constantly check the position of the mp3
// and restart after the initial mp3 gap.
var intervalVal:Number = setInterval( runMe , 1 );
function runMe():Void{
    if (track.position > placeToStop) {
        track.stop();
        track.start(leader/1000);
    }
} 
                 
            
            
        
            
        }
    }
}