gpt4 book ai didi

iphone - 音频将使 AVCaptureSession 终止

转载 作者:行者123 更新时间:2023-12-03 19:01:21 29 4
gpt4 key购买 nike

我编写了一个应用程序来从 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];

最佳答案

这对我有用:

- (void)setupAudio {
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
UInt32 doSetProperty = 1;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
[[AVAudioSession sharedInstance] setActive: YES error: nil];

}

关于iphone - 音频将使 AVCaptureSession 终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4710977/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com