Here is how id did it, with no noticeable delay. Main app:
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.utils.*;
public class MainApp extends MovieClip {
private var player:Player;
..........
public function MainApp() {
.......
player = new Player();
player.addEventListener(Player.EVENT_SOUND_COMPLETED, handleSoundCompleted);
......
}
private function handleSoundCompleted(event:Event):void {
player.setPosition(0);
player.play();
}
.................
Player class:
package {
import flash.events.*;
import flash.media.*;
import flash.net.*;
public class Player extends EventDispatcher {
private var sound:Sound;
private var channel:SoundChannel;
private var position:Number;
static const SOUND_VOLUME:Number = 0.75;
static const EVENT_SOUND_COMPLETED:String = "SOUND_COMPLETED";
public function Player() {
// init
sound = new ThemeSong();
position = 0;
// listeners
sound.addEventListener(IOErrorEvent.IO_ERROR, function(event:Event){trace(event)});
trace("Player initialized...");
}
public function play():void {
channel = sound.play(position);
channel.soundTransform = new SoundTransform(SOUND_VOLUME);
channel.addEventListener(Event.SOUND_COMPLETE, function(event:Event){dispatchEvent(new Event(EVENT_SOUND_COMPLETED));});
trace("Player playing..");
}
public function pause():void {
if (channel != null) {
channel.stop();
position = channel.position;
}
trace("Player paused..");
}
public function setPosition(pos:Number):void {
position = pos;
}
public function getPosition():Number {
if (channel == null) {
return 0;
} else {
return channel.position;
}
}
}
}
You did say that the mp3 file has no delay at beginning/end, but I suggest opening it with audacity, and make sure there is no delay.