Reputation: 151
I'm playing a sound file (mp3) and looping it 30 times.
soundChannel = soundLoop.play(0, 30);
I would like to display the current loop as a number in a textField. Have tried using an eventListener to determine when each loop restarts, but I think that Event.SOUND_COMPLETE dispatches when the sound is loaded and not for each repeated play.
I'd be grateful for some guidance in this area. Thanks.
Edit with working code Thanks to @Barış
var lastPosition:Number;
var loops:int=1;
var timerLoops:Timer = new Timer(1000);
timerLoops.addEventListener(TimerEvent.TIMER, startTimerLoops);
function startTimerLoops():void
{
timerLoops.start();
if(lastPosition > soundChannel.position)
loops++;
lastPosition = soundChannel.position;
trace("Playing " + loops + " of 30" + "-" + lastPosition);
}
Upvotes: 1
Views: 280
Reputation: 13532
soundChannel.position
is the time in milliseconds from the beginning of the sound. It is reset to 0 after the sound loops. You can track that to figure out if the sound looped.
Something like the following in your update/enterframe can work :
private function update():void
{
if(lastPosition > soundChannel.position)
loops++;
lastPosition = soundChannel.position;
}
Upvotes: 1