0

RubyMotion では、Mac 開発者ライブラリからこの要点を実装しようとして、スクリーン キャプチャに AVFoundation を使用しています。プログラムは、画面からビデオをキャプチャし、.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

私は何を間違っていますか?

4

1 に答える 1

1

ディスプレイ ID に間違った定数を使用しました。これは機能します:

input = AVCaptureScreenInput.alloc.initWithDisplayID(CGMainDisplayID())

于 2013-06-24T18:04:07.887 に答える