IPhone - AVAudioPlayer, kAudioSessionCategory_AmbientSound and iPod music
I am using the following audio session in my application div:
AudioSessionInitialize (NULL, NULL, NULL, self); UInt32 sessionCategory = kAudioSessionCategory_AmbientSound; AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), & sessionCategory); AudioSessionSetActive (true);
I want the user to be able to play iPod music and use my app at the same time, which is great, and works great ... my app ponders and allows iPod music to play.
The problem I am facing is ... after the user exits my app, navigates to the iPod app, and pauses when they return to my app, none of my sounds work. He, like everyone else, considers the iPod session active, even if he is not playing any music!
Basically I just want to reactivate the audio session after the iPod music is paused. Anyway, after ever playing music via an iPod app, I absolutely can't get my app sound back unless I recompile. :( Anyone have any ideas?
Edit: I forgot to mention that I am using the base implementation of the AVAudioPlayer class to play the audio of the application.
Thanks!
a source to share
Ok, just thought I'd keep everyone in place in case it helps someone else ... what I did was probably hackish, but it looks like it's a trick!
UInt32 isPlaying;
UInt32 propertySize = sizeof (isPlaying);
OSStatus status;
// check to see if their iPod music is playing
status = AudioSessionGetProperty (kAudioSessionProperty_OtherAudioIsPlaying, & propertySize, & isPlaying);
// set the session category accordingly
if (! isPlaying) {
NSLog (@ "... SoloAmbientSound");
UInt32 sessionCategory = kAudioSessionCategory_SoloAmbientSound;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), & sessionCategory);
} else {
NSLog (@ "... AmbientSound");
UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), & sessionCategory);
}
a source to share