check if audio is playing
Janne

Hi,
how I can check if audio is playing?

Example:

wade.app.musicVar = wade.playAudio('music.ogg', true);
// I need to know if this variable playing: wade.app.musicVar



Because if its not playing and I try to stop it with iPad or iPhone:
wade.stopAudio(wade.app.musicVar);
--> program/game will crash!
It works fine with Android and PC (without check if playing first), but iPhone need to audio playing first if try to stop it.

1 Comment
Gio

Hi Janne

Thanks for bringing this to my attention, I had no idea that that would cause a crash on iPhone and iPad. I will add a fix for the next release.

In the meantime I have a workaround for you. Not ideal, but it should work for the time being. When you call wade.playAudio, you can pass it a callback:

wade.playAudio(file, looping, callback)

The callback is called when the sound is finished playing. So you can keep track of your music state (whether it's playing or not), by doing something like this:

wade.app.musicPlaying = true;
wade.app.musicVar = wade.playAudio('music.ogg', false, function() {
    wade.app.musicPlaying = false;
});

// and some time later...

if (wade.app.musicPlaying) {
    wade.stopAudio(wade.app.musicVar)
};

I hope that helps

Post a reply
Add Attachment
Submit Reply
Login to Reply