Objective c 如何在AVFoundation中暂停屏幕录制
在Objective c 如何在AVFoundation中暂停屏幕录制,objective-c,macos,avfoundation,screen-recording,Objective C,Macos,Avfoundation,Screen Recording,在cocoa 对于启动视频,我使用此功能: -(void)takeScreenRecording:(CGRect)rect saveAtPath:(NSURL*)destPath { // Create a capture session mSession = [[AVCaptureSession alloc] init]; // Set the session preset as you wish mSession.sessionPreset = AVCapt
cocoa
对于启动视频,我使用此功能:
-(void)takeScreenRecording:(CGRect)rect saveAtPath:(NSURL*)destPath {
// Create a capture session
mSession = [[AVCaptureSession alloc] init];
// Set the session preset as you wish
mSession.sessionPreset = AVCaptureSessionPresetPhoto;
CGDirectDisplayID displayId = kCGDirectMainDisplay;
// Create a ScreenInput with the display and add it to the session
AVCaptureScreenInput *input =
[[AVCaptureScreenInput alloc] initWithDisplayID:displayId];
[input setCropRect:rect];
if (!input) {
mSession = nil;
return;
}
if ([mSession canAddInput:input])
[mSession addInput:input];
// Create a MovieFileOutput and add it to the session
mMovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];
if ([mSession canAddOutput:mMovieFileOutput])
[mSession addOutput:mMovieFileOutput];
// Start running the session
[mSession startRunning];
// Delete any existing movie file first
if ([[NSFileManager defaultManager] fileExistsAtPath:[destPath path]])
{
NSError *err;
if ( ![[NSFileManager defaultManager] removeItemAtPath:[destPath path]
error:&err] )
{
NSLog(@"Error deleting existing movie %@",[err localizedDescription]);
}
}
[mMovieFileOutput startRecordingToOutputFileURL:destPath
recordingDelegate:self];
}
对于停止屏幕录制,我使用以下功能:
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
fromConnections:(NSArray *)connections
error:(NSError *)error {
NSLog(@"Did finish recording to %@ due to error %@",
[outputFileURL description], [error description]);
[mSession stopRunning];
mSession = nil;
}
-(void)finishRecord {
// Stop recording to the destination movie file
NSLog(@"Stopping record");
[mMovieFileOutput stopRecording];
}
但我无法获得暂停功能的逻辑。有人能告诉我如何在录音时实现暂停屏幕吗?在下面的链接中找到问题的答案如果您在
SO
中提出任何问题,请查看您的格式,如果您已经找到问题帖子的答案作为答案。