Question

I'm using the following Audio Session in my app delegate:

  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 fine... my app bows out and allows the iPod music to play.

The issue I'm having is... after the user exits my app, goes into the iPod app and pauses, when they come back into my app, none of my sounds work. It's like it still thinks the iPod session is active, even though it isn't playing any music!

I basically just want to re-activate my audio session after iPod music has been paused. As it stands, after I've ever played music via the iPod app, I am totally unable to get my app's sounds back unless I recompile. :( Anyone have any ideas?

Edit: I forgot to mention I'm using a basic implementation of the AVAudioPlayer class to play my app's audio.

Thanks!

Was it helpful?

Solution

Okay just thought I'd keep everyone posted in case it helps someone else... what I did was probably kind of hackish, but seems to do the 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);
    }

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top