AVCaptureDevice 在模拟器上始终为空

zye*_*eek 6 record ios avcapturesession avcapturedevice

我正在尝试捕获实时麦克风音频数据。

我从苹果示例中获取了以下内容AVCaptureSession

AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];

AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];

NSError *error = nil;
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];

if (audioInput) {
    [captureSession addInput:audioInput];
}
else {
    // Handle the failure.
    NSLog(@"ERROR");
}
Run Code Online (Sandbox Code Playgroud)

audioCaptureDevice并且audioInput都是空的。

Oth*_*anT 3

模拟器无法将Mac麦克风作为来源。您需要使用真实设备来测试。