private void DidFinishCaptureAction(VideoCaptureDelegate captureDelegate, NSUrl outputUrl) { DispatchQueue.MainQueue.DispatchAsync(() => { if (captureDelegate?.IsBeingCancelled == true) { _videoRecordingDelegate?.DidCancelVideoRecording(this); } else { _videoRecordingDelegate?.DidFinishVideoRecording(this, outputUrl); } }); }
private void DidCaptureFail(VideoCaptureDelegate captureDelegate, NSError error, NSUrl outputUrl) { // we need to remove reference to the delegate so it can be deallocated _videoCaptureDelegate = null; DispatchQueue.MainQueue.DispatchAsync(() => { if (captureDelegate.RecordingWasInterrupted) { _videoRecordingDelegate?.DidInterruptVideoRecording(this, outputUrl, error); } else { _videoRecordingDelegate?.DidFailVideoRecording(this, error); } }); }
public void StartVideoRecording(bool shouldSaveVideoToLibrary) { if (_videoFileOutput == null) { Console.WriteLine("capture session: trying to record a video but no movie file output is set"); return; } _sessionQueue.DispatchAsync(() => { // if already recording do nothing if (_videoFileOutput.Recording) { Console.WriteLine( "capture session: trying to record a video but there is one already being recorded"); return; } // start recording to a temporary file. var outputFileName = new NSUuid().AsString(); var outputUrl = NSFileManager.DefaultManager.GetTemporaryDirectory().Append(outputFileName, false) .AppendPathExtension("mov"); var recordingDelegate = new VideoCaptureDelegate(DidStartCaptureAction, captureDelegate => DidFinishCaptureAction(captureDelegate, outputUrl), (captureDelegate, error) => DidCaptureFail(captureDelegate, error, outputUrl)) { ShouldSaveVideoToLibrary = shouldSaveVideoToLibrary }; _videoFileOutput.StartRecordingToOutputFile(outputUrl, recordingDelegate); _videoCaptureDelegate = recordingDelegate; }); }