Play sounds sequencially.

I’m just throwing this out there but does anyone have any thoughts on how to play sound files sequentially but ensure the second or third or whatever does not overlap / play while the previous one is playing.

I am using media.playeventsound (I am not preloadeding them with new media.newsound (as the the user can not play the sound again very quickly i.e. they are unique to each page).

But if you just kick off sound playeventsound’s they play together. I can attempt to control this with
timer.performwithdelay() but it’s does not seem the ideal method as the sound files all have different durations.

I know there is the alternate sound playing function but I though I had read that it is not really suited to this and is there for playing mp3’s

Any help would be appreciated.

Thanks
[import]uid: 5872 topic_id: 1737 reply_id: 301737[/import]

To call a completion listener each time the event sound is played, you can specify the listener in playEventSound:

media.playEventSound( “beep.caf”, onComplete )

See http://developer.anscamobile.com/content/multimedia-features

Note this doesn’t work on Android as the SoundPool API doesn’t notify when the sound ends. [import]uid: 54 topic_id: 1737 reply_id: 5124[/import]

ok great thanks this should help me for now (until I do a android port) but that will not be for some time and I’m sure there will be many for features in corona by then.

I have a similar question is it possible to get the duration of a sound file.
So I can kick off a sound file playing and have something moving on the screen but taking the same amount of time to move as the sound plays for. So the sounds duration replaces the 1500 (as I need these events to happen in sync).

media.playEventSound( flapOpenSID )
transition.to(pageFlap,{time=1500, x = pageFlap.x + pageFlap.width}) [import]uid: 5872 topic_id: 1737 reply_id: 5147[/import]

There is no way to get the duration of the sound file directly. You could play it once and use onComplete listener to get its duration.

-Tom [import]uid: 7559 topic_id: 1737 reply_id: 5184[/import]

You could get creative and open up the file and inspect the header and try to get its duration and or additional header information.

Look in http://mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm for information on how to obtain mp3 header information, such as, length, bit-rate, etc.

as well as the mp3 wikipedia entry

http://en.wikipedia.org/wiki/MP3

Carlos [import]uid: 24 topic_id: 1737 reply_id: 5236[/import]

On I though I had found a work around to do the tasks in parallel (play the sound file as the object is animating using the onStart Parametre of transition.to but in doing so now seem to have a problem with the completion listener of media.playEventSound
local function playAAAEA()
print("***You have entered the playAnswerAudioandEffectAudio()")
if g_AnswerAudio == 1 then --if audio answer is enabled

local function playEffect()
print("***You have entered the playEffect()")
media.playEventSound(answerEffectAudioG[currentPageNo][clueRandNo])
end

if g_AnswerEffectAudio == 1 then --if audio effect is on
media.playEventSound(speakAnswerG[currentPageNo][clueRandNo],playEffect)
else
media.playEventSound(speakAnswerG[currentPageNo][clueRandNo])
end
end
end

local function playDoorOpenSound()
print("***You have entered the playDoorOpenSound()")
media.playEventSound( flapOpenSID, playAAAEA())
–playAAAEA()
end
–media.playEventSound( flapOpenSID, playAAAEA)
–playAAAEA()
originalX = pageFlap.x – Record original x axis possition of flap
transition.to(pageFlap,{time=1500, x = pageFlap.x + pageFlap.width, onStart=playDoorOpenSound})

What happens as it currently stands is that the the sound flapOpenSID plays at the same time as the sound taken from the table answerEffectAudioG even thou the function playAAAEA is supposed to be called on complete of the sound file playback (I presume this is complete of playing the sound not on executing the code) because the two sounds answerEffectAudioG and answerEffectAudioG do in fact play sequentially and do not overlap and answerEffectAudioG is played from function playEffect() as a on completion listener.

Incidentally playEffect is called without () but in the piece of code
media.playEventSound( flapOpenSID, playAAAEA())
Calling the function playAAAEA will not work with ()
???
Thanks in advance
[import]uid: 5872 topic_id: 1737 reply_id: 5269[/import]

Why not open the sound file in a soudn editor (audacity for an example) and simply read there how long the file is. [import]uid: 5712 topic_id: 1737 reply_id: 5300[/import]

You specify the listener functions without the “()”. So media.playEventSound( flapOpenSID, playAAAEA) is the correct way to call playAAEA at the completion of the sound.

Are you saying that playAAEA is called before the sound ends?

-Tom [import]uid: 7559 topic_id: 1737 reply_id: 5333[/import]

Hi Tom,

I have refined the problem down to this:-

local flapOpenSID = media.newEventSound( “sound-opendoor.wav” )
local speechSID = media.newEventSound( “say-bat.wav”)
local effectSID = media.newEventSound( “sound-bat.wav”)

local function playEffect()
print("***You have entered the playEffect()")
media.playEventSound(“sound-bat.wav”)
end

local function playAnswer()
media.playEventSound(“say-bat.wav”,playEffect)
end

media.playEventSound(flapOpenSID , playAnswer)

If you use this code you will find that the only sound that plays is “sound-opendoor.wav” but if you replace the variable in the line media.playEventSound(flapOpenSID with the actual reference “sound-opendoor.wav” then all three play sequentially.
But I want to use the pre loaded sound via a soundID as that particular one is played often. This is a real problem give.

NOTE: On Android, there is a delay between loading a sound and when it is ready. playEventSound with a filename parameter is therefore not recommended and most often results in failure to play. Preload them with newEventSound.

Am I doing something wrong here?
[import]uid: 5872 topic_id: 1737 reply_id: 5404[/import]

Can you try this with the new Corona SDK and let me know if it works?

Are you testing this on iPhone or Android? There is a preload time needed on Android.

Thanks,
-Tom [import]uid: 7559 topic_id: 1737 reply_id: 6218[/import]