Music App (playing in background) breaks while rec

2019-07-15 12:03发布

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 recording https://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];


// Inform the device that we want to use the device orientation.
[[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

0条回答
登录 后发表回答