ani*_*tar 5 iphone audio avcapturesession
我写了一个应用程序来录制iPhone的视频.它工作正常,但有一个大问题.当AVCaptureSession开始运行并且用户尝试播放来自其库(iPod)的音频时.此操作将使AVCaptureSession终止.有什么想法可以阻止用户尝试播放音频或解决这个问题?
这是我的代码:
videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *videoDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:videoDevice error:nil];
AVCaptureDeviceInput *audioDeviceInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];
movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
captureSession = [[AVCaptureSession alloc] init];
[captureSession beginConfiguration];
[captureSession setSessionPreset:AVCaptureSessionPresetHigh];
[captureSession addInput:videoDeviceInput];
[captureSession addInput:audioDeviceInput];
[captureSession addOutput:movieFileOutput];
[captureSession commitConfiguration];
[captureSession startRunning];
Run Code Online (Sandbox Code Playgroud)
您需要使用NSNotificationCenter. 使用下面的代码(我还包括了一些其他有用的方法),并编写一个方法来AVCaptureSessionWasInterruptedNotification以任何方式处理捕获中断。我希望这有帮助。
NSNotificationCenter *notify = [NSNotificationCenter defaultCenter];
[notify addObserver: self selector: @selector(onVideoError:) name: AVCaptureSessionRuntimeErrorNotification object: captureSession];
[notify addObserver: self selector: @selector(onVideoInterrupted:) name: AVCaptureSessionWasInterruptedNotification object: captureSession];
[notify addObserver: self selector: @selector(onVideoEnded:) name: AVCaptureSessionInterruptionEndedNotification object: captureSession];
[notify addObserver: self selector: @selector(onVideoDidStopRunning:) name: AVCaptureSessionDidStopRunningNotification object: captureSession];
[notify addObserver: self selector: @selector(onVideoStart:) name: AVCaptureSessionDidStartRunningNotification object: captureSession];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2117 次 |
| 最近记录: |