Looking for a good way to seamless switch between background tracks. I have a few bg loop tracks that can be played one after the other and fit nicely, and I would like to be able to use this for various parts of the game, and when one ends, start another one. Is this possible using cocos denshion, or am going to have to roll my own? And if I have to roll my own, some suggestions on where to go for info? The tracks are fairly short, 15 sec and 8 sec, so would it possible to do it loading them as effects?
Seamless switch between background tracks
(11 posts) (6 voices)-
Posted 1 year ago #
-
If they are only 15 and 8 seconds I would be inclined to just use effects. If you can live with mono and 22050 Hz sample rate all the more better as that will cut down the memory use dramatically.
If you are really pushed for memory then you could use the "spare" CDLongAudioSource, there have been numerous discussions on this which I'm sure you can easily find.
However, the effects approach will give you a much tighter result as the latency is very low.
Posted 1 year ago # -
What would be a good approach to detect when the effect has ended playing, so I know to play the next effect? I have thought of using actions, but I am not sure how well it would work.
Posted 1 year ago # -
There is an ability to set a callback for when background music completes, maybe you can adapt it to your needs. It looks something like
[[CDAudioManager sharedManager] setBackgroundMusicCompletionListener:self selector:@selector(...)];Posted 1 year ago # -
Just found this:
http://www.cocos2d-iphone.org/forum/topic/7693 callback on CDLongAudioSource. I'll have to try this and see how it works. Thanks for the ideas guys!
Posted 1 year ago # -
@sabshire - OpenAL (as used by effects) has no call back for completion so you need to use polling. One way to do it is create a CDSoundSource object for your effect and keep checking the playing property until it returns false.
Edit: if you want seamless transitioning from one track to the other then I doubt CDLongAudioSource (which uses AVAudioPlayer) will give acceptable results.
Posted 1 year ago # -
Thanks Steve. I'll give it a go
Posted 1 year ago # -
Steve, using the CDSoundSource polling method works well. Thanks for the idea! Just what I needed.
Posted 1 year ago # -
@sabshire Sorry to revisit this thread again but I'm just looking into doing something like you wanted to do with your background music, play a track made up of discrete parts and I can dynamically start.
Are you using the SimpleAudioEngine at all? I call preloadEffect, then soundSourceForFile, then in my main loop call playEffect if sourceSource.isPlaying returns NO. It seems that it's ALWAYS returning NO so the sound just restarts rapidly.
Anyone have any ideas or do I need to really switch to the CDSoundEngine to really make it work?
Posted 1 year ago # -
hi.....guys
i play background sound for my game using,
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"backgroundMusic.m4a"];
[[SimpleAudioEngine sharedEngine] setEffectsVolume:0.8f];i need slow motion effect for the above sound.how can i do that...?
thanks in advance.
Posted 4 months ago #
Reply
You must log in to post.