【发布时间】:2010-08-16 17:58:21
【问题描述】:
使用 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”。我能说的就是告诉我一些我不知道的事情。有人知道为什么会话没有运行吗?
【问题讨论】:
标签: iphone video ios4 video-streaming video-capture