Reputation: 1624
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?
Upvotes: 0
Views: 4054
Reputation: 5781
Using the TimerEvent to loop will not be accurate enough because the way events are triggered in the Flash Player.
The easiest way to play a seamless "infinite" loop is to:
There are more powerful solutions as well that might be of interest: Prefered method for looping sound flash as3
Upvotes: 2