使用AVCaptureSession录制video时,音乐应用程序(在后台播放)会中断
我正在开发像应用程序一样的function。 在我的应用程序中,音乐应用程序在后台运行,我的应用程序处于前台状态。 我必须同时在后台运行音乐应用程序捕捉video。
问题: – 当我的应用程序进入前台状态,音乐应用程序audio暂停一秒钟,然后继续。 同样的问题出现时,用户点击HOMEbutton,应用程序进入后台状态和音乐应用程序audiorest一秒钟。
我已经下载了用于录制的苹果示例代码https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112
下载后,在AppDelegate中完成了以下更改
在AppDelegate.h中
导入AVFoundation
@property(nonatomic,retain)AVAudioSession * session1;
在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];
在AAPLCameraViewController.m中
两个属性已被添加
self.session.usesApplicationAudioSession = TRUE; self.session.automaticallyConfiguresApplicationAudioSession = FALSE;
其他方式
我已经尝试使用SCRecorder库,但同样的问题是与该库。 源代码可以从Github https://github.com/sumitsharma/SCRecorderDemo进入