在 RubyMotion 中,我使用 AVFoundation 进行屏幕捕捉,试图从 Mac 开发者库中实现这个要点。该程序应从屏幕捕获视频并写入 .mov 文件。
我不太明白为什么会出现此错误:
* -[AVCaptureMovieFileOutput startRecordingToOutputFileURL:recordingDelegate:] - 没有活动/启用的连接。
简单的代码是:
# Setup recording pipeline
@session = AVCaptureSession.alloc.init
@session.sessionPreset = AVCaptureSessionPresetMedium
input = AVCaptureScreenInput.alloc.initWithDisplayID(KCGDirectMainDisplay)
@session.addInput(input)
movieFileOutput = AVCaptureMovieFileOutput.alloc.init
if @session.canAddOutput(movieFileOutput)
@session.addOutput(movieFileOutput)
else
Logger.error "Could not add ouput #{movieFileOutput}"
end
@session.startRunning()
# Delete exisiting file
fileManager = NSFileManager.defaultManager
path = "~/Desktop/video.mov"
if fileManager.fileExistsAtPath(path)
err = Pointer.new(:object)
unless fileManager.defaultManager.removeItemAtPath(path, error:err)
Logger.error "Can't delete existing movie"
end
end
# Start recording
movieFileOutput.startRecordingToOutputFileURL(NSURL.fileURLWithPath(path), recordingDelegate:self) # <--- Problem
我在做什么不正确?