Sequencing sound effect playback

Does anyone have any ideas as to how I can sequence the playback of sound files with SimpleAudioEngine?

I need to dynamically put together a spoken sentence from multiple sound files. The way I’ve done it with cocos2d on Objective C is with a callback so I know when the file has finished playing, but it doesn’t seem possible in C++ (though it may be, I’m not really an expert!). The only way I can see to do it is to sequence the sounds with a CCDelay between each one of the length of the file, but I’m not sure if this is a good idea or not. I’ll write some code to see if this actually works, but wondering if anyone has any better ideas before I start?

Edit : Tried sequencing using the length of the sound file as a CCDelayTime, seems to work quite well. Is there a good reason not to do this? Will be sequencing about 3-4 files.

Hi James,

I checked and there is no direct method to add a callback method for SimpleSoundEngine. Though you can still add it for iOS platform but for Android it would not going to work as code is totally different. iOS uses CDAudioEngine and Android uses AudioPlayer. So I think CCDelayTime is the best method at the time. The only glitch I can see it with slow devices where audio playback / CCDelay may go out of sync. Or even on high performance devices, if you try to load heavy objects in the background and at the same time using audio playback with CCDelay technique. I am not very sure if the bug is going appear or how easy to produce on a device or even if there is any bug (may be I am over concern :))

One more thing, are you trying it with background music or audio files only? In case, if you don’t have the background music then you can play the audio files as music (without loop) and keep on checking if background music is still playing in the update method. Not sure if this would have satisfactory results though.

Paras Mendiratta wrote:

Hi James,
>
I checked and there is no direct method to add a callback method for SimpleSoundEngine. Though you can still add it for iOS platform but for Android it would not going to work as code is totally different. iOS uses CDAudioEngine and Android uses AudioPlayer. So I think CCDelayTime is the best method at the time. The only glitch I can see it with slow devices where audio playback / CCDelay may go out of sync. Or even on high performance devices, if you try to load heavy objects in the background and at the same time using audio playback with CCDelay technique. I am not very sure if the bug is going appear or how easy to produce on a device or even if there is any bug (may be I am over concern :))
>
One more thing, are you trying it with background music or audio files only? In case, if you don’t have the background music then you can play the audio files as music (without loop) and keep on checking if background music is still playing in the update method. Not sure if this would have satisfactory results though.

That’s very useful thanks! I’ve tried it with CCDelayTime and it seems to work ok, I won’t be doing much in the background so it’ll hopefully be ok. Will test on an old device I have anyway. The background music way could be an option as well as we’re not playing music at the same time.