Skip to main content
Known Participant
September 12, 2011
Answered

Is there a way to now if a sound is still playing?

  • September 12, 2011
  • 1 reply
  • 1266 views

Hi

I'm using varname.play() to play a sound (mp3)

But I need to stop my App until the sound finished of playing.. Anybody knows if there is a way to know if a sound complete to reproduce?

Thank you

This topic has been closed for replies.
Correct answer The_Preacher1

Dear Chorrillanop23,

I am not sure I comprehend the delay you are speaking of.  I have used this to like words to make phrases with no noticiable delay on iOS devices.  I would recommend that you create multiple channels if you need to have more than one sound clip running at the same time.  Just add

var channel1:SoundChannel;

var channel2:SoundChannel;

var channel3:SoundChannel;

channel1.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete1);

channel2.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete2);

channel3.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete3);

// Now just add the 3 functions.

Please help me understand better the delay you are speaking of.  Could you create a small sample fla file that demonstrates this issue?

Grace & Peace!

jim

1 reply

The_Preacher1
Inspiring
September 12, 2011

I would recommend that you do something like this:

// create a SoundChannel variable

var channel:SoundChannel;

// in the library set the AS linkage for your mp3 file to myMP3sound (or change this to match yours)

var myMP3sound:Sound = new WhatSayHorse_mp3();

// play the sound using a call like this:

channel = myMP3sound.play();

// add an event listener to call a function when the sound has completed

channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);

// Add the fuction and put whatever code in it that you need.

function onPlaybackComplete(evt:Event):void {

       // add the code here that you want executed on sound finished playing.

}

//---------------------------------------

//  I hope this helps!

//  Grace & Peace to you!

//  jim

//------------------------------------

Known Participant
September 13, 2011

Thank you!

Works great ...