I am trying to get my audio application to play in the background. So far, I have added the “application plays audio” to the “required background modes” in info.plist, as well as the following code before starting my sound generator:
AudioSessionInitialize(NULL, kCFRunLoopDefaultMode, &interruptionListener, sgD); AudioSessionAddPropertyListener(kAudioSessionProperty_AudioRouteChange, &routeChangeListener, sgD); // select "Playback" audio session category NSError *setCategoryError = nil; [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError]; OSStatus propertySetError = 0; UInt32 category = kAudioSessionCategory_MediaPlayback; propertySetError = AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory, sizeof (category), &category ); AudioSessionSetActive(true);
However, this only works when switching to another application or to the iPod home screen. When I turn off the screen, it also turns off my audio output, which is definitely not what I want. However, all the tutorials / documentation / answers to stackoverflow questions seem to indicate that sound is saved when the screen turns off automatically when you get background sound for work. Does anyone have a hint of me? Thank you very much in advance! Fritz
source share