Game Development Community

Pausing MP3 Audio in iTGB?

by Dave Calabrese · in iTorque 2D · 07/29/2009 (9:33 am) · 5 replies

I'm attempting to make my game music pause when the game is paused, then resume when the game is unpaused. This functionality is not default to iTGB, so I have been working on adding it in. Looking through the code and the iPhone API code, it seems like it should be as simple as adding the following functions to iPhoneStreamSource.cc:

bool iPhoneStreamSource::pause() {
	SoundEngine::SoundEngine_StopBackgroundMusic( false );
	return true;
}

bool iPhoneStreamSource::unpause() {
	SoundEngine::SoundEngine_StartBackgroundMusic();
	return true;
}

Pause works to stop the music, but unpause does not work. I have tried a few variations on this code, but have had no luck yet. Could anyone please advise on how to pause and unpause an iPhoneStreamSource?

Thanks all,
-Dave Calabrese

#1
07/29/2009 (9:40 am)
Is this for strict pause or as well going to sleep?

In the later case you potentially must reinitialize the SoundEngine first before it will work again as sound normally is "killed" when applications (other than the ipod player) go to sleep.
In that case I think you actually should get an error printed to the console if it fails too (from BackgroundTrackMgr::Start, Error priming queue)
#2
07/29/2009 (9:43 am)
This is just for pausing the game. There is an on-screen pause button and we need the gameplay and the music to both pause when it is pressed. However, I can see an issue if the device goes to sleep while the game is paused, so I'll probably need to do a check when we do the music unpause to see if the SoundEngine is initialized, and it not re-init it.
#3
07/29/2009 (7:10 pm)
Does this help?

http://www.iphonedevsdk.com/forum/iphone-sdk-development/7487-help-soundengine-h.html
#4
07/29/2009 (11:44 pm)
Afraid not... I got an error saying "Stream is already playing!".
#5
07/31/2009 (1:40 pm)
Ok.. I got it to work, and I wrote a resource that explains how to do it:

www.garagegames.com/community/resources/view/17987