我试图让Apple的AVScreenShack example project在OS X 10.8.2上运行。
当我运行应用程序并触发录制(调用startRecording
)时,会发生一系列奇怪的事件:
captureOutput:didStartRecordingToOutputFileAtURL:fromConnections:
从不调用 当我触发stopRecording
时:
NSLog
调用显示captureMovieFileOutput
对象带有有效文件URL(指向桌面上的临时文件)captureOutput:didFinishRecordingToOutputFileAtURL:fromConnections:error:
从不调用 我在输出控制台中看不到任何错误。有没有什么方法可以进一步有效地调试它?
相关代码如下。我没有修改它(但在这里省略了不必要的部分)。
- (BOOL)createCaptureSession:(NSError **)outError
{
NSLog(@"createCaptureSession start");
/* Create a capture session. */
self.captureSession = [[AVCaptureSession alloc] init];
// ...
/* Add the main display as a capture input. */
display = CGMainDisplayID();
self.captureScreenInput = [[AVCaptureScreenInput alloc]
initWithDisplayID:display];
if ([self.captureSession canAddInput:self.captureScreenInput]) {
[self.captureSession addInput:self.captureScreenInput];
} else {
return NO;
}
/* Add a movie file output + delegate. */
captureMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
[captureMovieFileOutput setDelegate:self];
if ([self.captureSession canAddOutput:captureMovieFileOutput]) {
[self.captureSession addOutput:captureMovieFileOutput];
} else {
return NO;
}
/* Register for notifications of errors during the capture session so we
can display an alert. */
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(captureSessionRuntimeErrorDidOccur:)
name:AVCaptureSessionRuntimeErrorNotification
object:self.captureSession];
NSLog(@"createCaptureSession finish w/o errors");
return YES;
}
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didStartRecordingToOutputFileAtURL:(NSURL *)fileURL
fromConnections:(NSArray *)connections {
NSLog(@"starting output");
NSLog(@"%@", captureMovieFileOutput.outputFileURL);
}
/* Informs the delegate when all pending data has been written to the output file. */
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error
{
NSLog(@"didFinish");
if (error)
{
[self presentError:error];
return;
}
[[NSWorkspace sharedWorkspace] openURL:outputFileURL];
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
NSLog(@"about to start running the session %@", self.captureSession);
/* Start the capture session running. */
[self.captureSession startRunning];
}
/* Called when the user presses the 'Start' button to start a recording. */
- (IBAction)startRecording:(id)sender
{
NSLog(@"startRecording");
char *tempNameBytes = tempnam([[@"~/Desktop/" stringByStandardizingPath]
fileSystemRepresentation], "AVScreenShack_");
NSString *tempName = [[NSString alloc]
initWithBytesNoCopy:tempNameBytes
length:strlen(tempNameBytes)
encoding:NSUTF8StringEncoding
freeWhenDone:YES];
/* Starts recording to a given URL. */
[captureMovieFileOutput
startRecordingToOutputFileURL:[NSURL fileURLWithPath:[tempName stringByAppendingPathExtension:@"mov"]]
recordingDelegate:self];
}
/* Called when the user presses the 'Stop' button to stop a recording. */
- (IBAction)stopRecording:(id)sender
{
NSLog(@"about to stop from URL: %@", captureMovieFileOutput.outputFileURL);
[captureMovieFileOutput stopRecording];
}
/* Called when the document is closed. */
- (void)close
{
NSLog(@"about to stop from URL: %@", captureMovieFileOutput.outputFileURL);
/* Stop the capture session running. */
[self.captureSession stopRunning];
[super close];
}
以上程序的日志输出如下。请注意,“didFinish”日志调用从未进行过,也没有“开始输出”。
2013-04-20 16:00:01.908 AVScreenShack[8950:303] createCaptureSession start
2013-04-20 16:00:01.912 AVScreenShack[8950:303] createCaptureSession finish w/o errors
2013-04-20 16:00:02.131 AVScreenShack[8950:303] about to start running the session <AVCaptureSession: 0x100618e70 [AVCaptureSessionPresetHigh]>
2013-04-20 16:00:10.936 AVScreenShack[8950:303] startRecording
2013-04-20 16:00:10.936 AVScreenShack[8950:303] Minimum Frame Duration: 0.066667, Crop Rect: {{0, 0}, {0, 0}}, Scale Factor: 1.000000, Capture Mouse Clicks: No, Capture Mouse Cursor: Yes, Remove Duplicate Frames: Yes
2013-04-20 16:00:15.648 AVScreenShack[8950:303] about to stop from URL: file://localhost/Users/jon/Desktop/AVScreenShack_Y2DUaA.mov