I made a function which loops the mp3 infinitely until I stop it:
private function loopSound(a:Class, lead:Number, trail:Number) {
var b = new a();
var sChannel = new SoundChannel();
var timer:Timer = new Timer(b.length - lead - trail, 1);
sChannel = b.play(lead);
timer.addEventListener(TimerEvent.TIMER_COMPLETE, function r(e:TimerEvent) { loopSound(a, lead, trail); } );
timer.start();
}
The problem with this function is that it doesn't loop correctly. Though my calculating is correct(from my view), flash doesn't calculate the positions correctly. Any idea how to achieve flawless mp3 loop?
- lead = gap at the beginning in ms (27.375ms in my case)
- trail = gap at the end in ms (20.278ms in my case)