IOS background sound stops when the screen is locked

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

+6
source share
1 answer

This article explains the problem:

Technical Q & A QA1606 Schedule processing audio devices. Sound playback continues when the screen is locked

Basically, you just need to make sure that you have installed all AudioUnits to support 4096 fragments:

 // set the mixer unit to handle 4096 samples per slice since we want to keep rendering during screen lock UInt32 maxFPS = 4096; AudioUnitSetProperty( mMixer, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Global, 0, &maxFPS, sizeof(maxFPS)); 
+5
source

Source: https://habr.com/ru/post/918370/


All Articles