捕获相机和音频输入时出错
使用 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”。我只能说告诉我一些我不知道的事情。有人知道为什么会话没有运行吗?
using some of the nifty new APIs in iOS4 i am trying to capture input from the iPhone's camera and microphone and save it to a file. below is the code i am using.
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);
}
when the didFinishRecordingToOutputFileAtURL comes back i get a cryptic error response.
Error Domain=AVFoundationErrorDomain Code=-11803 "Cannot Record" UserInfo=0x152f70 {NSLocalizedRecoverySuggestion=Try recording again., AVErrorRecordingSuccessfullyFinishedKey=false, NSLocalizedDescription=Cannot Record}
the error code −11803 means "AVErrorSessionNotRunning". all i can say is tell me something i don't know. anyone have any idea why the session is not running?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
[videoOutput startRecordingToOutputFileURL:saveLocationURL reportingDelegate:self];
之前调用[captureSession startRunning];
。Call
[captureSession startRunning];
before[videoOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];
.