使用AVCaptureSession录制视频时,音乐应用程序(在后台播放)中断

时间:2015-10-12 09:02:59

标签: ios objective-c iphone avfoundation avcapturesession

我正在开发类似功能的应用程序。在我的应用程序中,音乐应用程序在后台运行,我的应用程序处于前台状态。我必须与在后台运行的音乐应用程序同时捕获视频。

问题: - 当我的应用程序进入前台状态时,音乐应用程序音频会暂停一秒钟然后继续。当用户点击 HOME 按钮,应用程序进入后台状态并且音乐应用程序音频中断一秒钟时,会出现同样的问题。

我已下载了用于录制https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010112

的Apple示例代码

下载后,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 Library ,但该库存在同样的问题。可以从Github访问源代码 https://github.com/sumitsharma/SCRecorderDemo

0 个答案:

没有答案
相关问题