Music App (playing in background) breaks while recording video using AVCaptureSession

I am working on snapchat app like functionality. In my application, music app is running in the background and my app is in foreground state. I have to capture video simultaneously with music app running in the background.

Problem :- when my app comes in foreground state, the music app audio break for a second and then continue. Same problem arises when user tap HOME button, app went to background state and the music app audio break for a second.

I have downloaded the apple sample code for recordinghttps://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112

After downloading following changes have been done in the AppDelegate


In AppDelegate.h

import AVFoundation

@property (nonatomic, retain) AVAudioSession *session1;

In AppDelegate.m

self.session1 = [AVAudioSession sharedInstance];
[self.session1 setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker | AVAudioSessionCategoryOptionMixWithOthers | AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers error:nil]; [self.session1 setActive:YES error:nil]; / [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];


In AAPLCameraViewController.m
Two properties have been added

self.session.usesApplicationAudioSession=TRUE;

self.session.automaticallyConfiguresApplicationAudioSession=FALSE;


Another Way


I have tried using SCRecorder Library but same issue is coming with that library. Source code can be reached from Github https://github.com/sumitsharma/SCRecorderDemo


Till now I am not able to find a solution, your help/suggesstions are solicitated.

Replies

Unfortunately, switching from audio output-only routes (such as Ambient) to input+output route (PlayAndRecord) causes a significant enough reconfiguration of the audio routing subsystem to cause a playback glitch. There is no current workaround.

I'm having this exact same problem. Is a workaround for this in the plans?