gpt4 book ai didi

iphone - 捕获相机和音频输入时出错

转载 作者:行者123 更新时间:2023-11-28 21:40:29 25 4
gpt4 key购买 nike

使用 iOS4 中一些漂亮的新 API,我试图从 iPhone 的摄像头和麦克风捕获输入并将其保存到文件中。下面是我正在使用的代码。

AVCaptureSession* captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&error];
AVCaptureDeviceInput* videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:captDevice error:&error];
AVCaptureMovieFileOutput * videoOutput = [[AVCaptureMovieFileOutput alloc] init];

if (videoInput && videoOutput && audioInput)
{
[captureSession addInput:audioInput];
[captureSession addInput:videoInput];
[captureSession addOutput:videoOutput];
if([captDevice lockForConfiguration:&error])
{
if ([captDevice hasTorch])
captDevice.torchMode = AVCaptureTorchModeOn;

[captDevice unlockForConfiguration];
}
else
{
NSLog(@"Could not lock device for config error: %@", error);
}

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSURL* saveLocationURL = [[NSURL alloc] initFileURLWithPath:[NSString stringWithFormat:@"%@/movie.mov", documentsDirectory]];

[videoOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];
[captureSession startRunning];

[saveLocationURL release];
}
else
{
NSLog(@"Video Error: %@", error);
}

当 didFinishRecordingToOutputFileAtURL 返回时,我收到一个神秘的错误响应。

Error Domain=AVFoundationErrorDomain Code=-11803 "Cannot Record" UserInfo=0x152f70 {NSLocalizedRecoverySuggestion=Try recording again., AVErrorRecordingSuccessfullyFinishedKey=false, NSLocalizedDescription=Cannot Record}

错误代码 −11803 表示“AVErrorSessionNotRunning”。我只能说告诉我一些我不知道的事情。有人知道为什么 session 没有运行吗?

最佳答案

[videoOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];之前调用[captureSession startRunning];

关于iphone - 捕获相机和音频输入时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3495879/

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