Sur*_*eet 7 objective-c ios avcapturesession avaudiosession
我使用AVCaptureSession创建了一个相机.我已经为照片和视频录制模式配置了它.
相机和应用程序运行正常.此外,我还允许播放背景音乐 (如果用户在iPhone中使用音乐应用程序播放歌曲),同时打开相机或录制视频.它也工作正常.(附图2)
我借助此代码允许背景音乐播放
AVAudioSession *session1 = [AVAudioSession sharedInstance];
[session1 setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error:nil];
[session1 setActive:YES error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
Run Code Online (Sandbox Code Playgroud)
现在,如果我接到一个电话,通过点击主页按钮并打开应用程序来最小化电话呼叫屏幕并想要打开相机屏幕来捕获图像/录制视频,它会打开但冻结图像(附加图像(1)).
现在我的要求是,我想在通话时捕捉图像/录制视频.我寻找了另一个应用程序,Snapchat正在做同样的事情,我可以在通话时录制视频.
您需要使用AVCaptureSessionWasInterruptedNotification和AVCaptureSessionInterruptionEndedNotification回调并在会话中断时断开音频捕获:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionWasInterrupted:) name:AVCaptureSessionWasInterruptedNotification object:self.session];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionInterruptionEnded:) name:AVCaptureSessionInterruptionEndedNotification object:self.session];
// note that self.session is an AVCaptureSession
Run Code Online (Sandbox Code Playgroud)
-
- (void)sessionWasInterrupted:(NSNotification *)notification {
NSLog(@"session was interrupted");
AVCaptureDevice *device = [[self audioInput] device];
if ([device hasMediaType:AVMediaTypeAudio]) {
[[self session] removeInput:[self audioInput]];
[self setAudioInput:nil];
}
}
- (void)sessionInterruptionEnded:(NSNotification *)notification {
NSLog(@"session interuption ended");
}
// note that [self audioInput] is a getter for an AVCaptureDeviceInput
Run Code Online (Sandbox Code Playgroud)
这将允许相机继续运行并允许其捕获静态/无声视频
现在至于如何在通话结束后重新连接音频..如果您弄清楚了,请告诉我,从 iOS 10 开始似乎不可能:通话结束时回调?(恢复 AVCaptureSession)
| 归档时间: |
|
| 查看次数: |
1092 次 |
| 最近记录: |