public override void WindowControllerDidLoadNib(NSWindowController windowController) { base.WindowControllerDidLoadNib(windowController); // Create session session = new QTCaptureSession(); // Attach preview to session captureView.CaptureSession = session; captureView.WillDisplayImage = WillDisplayImage; // Attach outputs to session movieFileOutput = new QTCaptureMovieFileOutput(); movieFileOutput.WillStartRecording += WillStartRecording; movieFileOutput.DidStartRecording += DidStartRecording; movieFileOutput.ShouldChangeOutputFile = ShouldChangeOutputFile; movieFileOutput.MustChangeOutputFile += MustChangeOutputFile; // These ones we care about, some notifications movieFileOutput.WillFinishRecording += WillFinishRecording; movieFileOutput.DidFinishRecording += DidFinishRecording; NSError error; session.AddOutput(movieFileOutput, out error); audioPreviewOutput = new QTCaptureAudioPreviewOutput(); audioPreviewOutput.Volume = 0; session.AddOutput(audioPreviewOutput, out error); if (VideoDevices.Length > 0) { SelectedVideoDevice = VideoDevices [0]; } if (AudioDevices.Length > 0) { SelectedAudioDevice = AudioDevices [0]; } session.StartRunning(); // events: devices added/removed AddObserver(QTCaptureDevice.WasConnectedNotification, DevicesDidChange); AddObserver(QTCaptureDevice.WasDisconnectedNotification, DevicesDidChange); // events: connection format changes AddObserver(QTCaptureConnection.FormatDescriptionDidChangeNotification, FormatDidChange); AddObserver(QTCaptureConnection.FormatDescriptionWillChangeNotification, FormatWillChange); AddObserver(QTCaptureDevice.AttributeWillChangeNotification, AttributeWillChange); AddObserver(QTCaptureDevice.AttributeDidChangeNotification, AttributeDidChange); audioLevelTimer = NSTimer.CreateRepeatingScheduledTimer(0.1, UpdateAudioLevels); }
public override void WindowControllerDidLoadNib (NSWindowController windowController) { base.WindowControllerDidLoadNib (windowController); // Create session session = new QTCaptureSession (); // Attach preview to session captureView.CaptureSession = session; captureView.WillDisplayImage = WillDisplayImage; // Attach outputs to session movieFileOutput = new QTCaptureMovieFileOutput (); movieFileOutput.WillStartRecording += WillStartRecording; movieFileOutput.DidStartRecording += DidStartRecording; movieFileOutput.ShouldChangeOutputFile = ShouldChangeOutputFile; movieFileOutput.MustChangeOutputFile += MustChangeOutputFile; // These ones we care about, some notifications movieFileOutput.WillFinishRecording += WillFinishRecording; movieFileOutput.DidFinishRecording += DidFinishRecording; NSError error; session.AddOutput (movieFileOutput, out error); audioPreviewOutput = new QTCaptureAudioPreviewOutput (); audioPreviewOutput.Volume = 0; session.AddOutput (audioPreviewOutput, out error); if (VideoDevices.Length > 0) SelectedVideoDevice = VideoDevices [0]; if (AudioDevices.Length > 0) SelectedAudioDevice = AudioDevices [0]; session.StartRunning (); // events: devices added/removed AddObserver (QTCaptureDevice.WasConnectedNotification, DevicesDidChange); AddObserver (QTCaptureDevice.WasDisconnectedNotification, DevicesDidChange); // events: connection format changes AddObserver (QTCaptureConnection.FormatDescriptionDidChangeNotification, FormatDidChange); AddObserver (QTCaptureConnection.FormatDescriptionWillChangeNotification, FormatWillChange); AddObserver (QTCaptureDevice.AttributeWillChangeNotification, AttributeWillChange); AddObserver (QTCaptureDevice.AttributeDidChangeNotification, AttributeDidChange); audioLevelTimer = NSTimer.CreateRepeatingScheduledTimer (0.1, UpdateAudioLevels); }
public override void WindowControllerDidLoadNib (NSWindowController windowController) { base.WindowControllerDidLoadNib (windowController); // A reference to the window controller must be kept on the managed side // to keep the object from being GC'd so that the delegates below resolve. // Don't remove unless the framework is updated to track the reference. this.windowController = windowController; NSError err; windowController.Window.WillClose += delegate { if (captureSession != null) captureSession.StopRunning (); var dev = captureInput.Device; if (dev.IsOpen) dev.Close (); }; // Create a movie, and store the information in memory on an NSMutableData movie = new QTMovie (new NSMutableData (1), out err); if (movie == null){ NSAlert.WithError (err).RunModal (); return; } movieView.Movie = movie; // Find video device captureSession = new QTCaptureSession (); var device = QTCaptureDevice.GetDefaultInputDevice (QTMediaType.Video); if (!device.Open (out err)){ NSAlert.WithError (err).RunModal (); return; } // Add device input captureInput = new QTCaptureDeviceInput (device); if (!captureSession.AddInput (captureInput, out err)){ NSAlert.WithError (err).RunModal (); return; } // Create decompressor for video output, to get raw frames decompressedVideo = new QTCaptureDecompressedVideoOutput (); decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) { lock (this){ currentImage = e.VideoFrame; } }; if (!captureSession.AddOutput (decompressedVideo, out err)){ NSAlert.WithError (err).RunModal (); return; } // Activate preview captureView.CaptureSession = captureSession; // Start running. captureSession.StartRunning (); }
public override void WindowControllerDidLoadNib(NSWindowController windowController) { NSError err; // Create a movie, and store the information in memory on an NSMutableData movie = new QTMovie(new NSMutableData(1), out err); if (movie == null) { NSAlert.WithError(err).RunModal(); return; } movieView.Movie = movie; // Find video device captureSession = new QTCaptureSession(); var device = QTCaptureDevice.GetDefaultInputDevice(QTMediaType.Video); if (device == null) { new NSAlert { MessageText = "You do not have a camera connected." }.BeginSheet(windowController.Window); return; } else if (!device.Open(out err)) { NSAlert.WithError(err).BeginSheet(windowController.Window); return; } // Add device input captureInput = new QTCaptureDeviceInput(device); if (!captureSession.AddInput(captureInput, out err)) { NSAlert.WithError(err).BeginSheet(windowController.Window); return; } // Create decompressor for video output, to get raw frames decompressedVideo = new QTCaptureDecompressedVideoOutput(); decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) { lock (this) { currentImage = e.VideoFrame; } }; if (!captureSession.AddOutput(decompressedVideo, out err)) { NSAlert.WithError(err).BeginSheet(windowController.Window); return; } // Activate preview captureView.CaptureSession = captureSession; // Start running. captureSession.StartRunning(); }
public override void WindowControllerDidLoadNib (NSWindowController windowController) { NSError err; // Create a movie, and store the information in memory on an NSMutableData movie = new QTMovie (new NSMutableData (1), out err); if (movie == null) { NSAlert.WithError (err).RunModal (); return; } movieView.Movie = movie; // Find video device captureSession = new QTCaptureSession (); var device = QTCaptureDevice.GetDefaultInputDevice (QTMediaType.Video); if (device == null) { new NSAlert { MessageText = "You do not have a camera connected." }.BeginSheet (windowController.Window); return; } else if (!device.Open (out err)) { NSAlert.WithError (err).BeginSheet (windowController.Window); return; } // Add device input captureInput = new QTCaptureDeviceInput (device); if (!captureSession.AddInput (captureInput, out err)) { NSAlert.WithError (err).BeginSheet (windowController.Window); return; } // Create decompressor for video output, to get raw frames decompressedVideo = new QTCaptureDecompressedVideoOutput (); decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) { lock (this) { currentImage = e.VideoFrame; } }; if (!captureSession.AddOutput (decompressedVideo, out err)) { NSAlert.WithError (err).BeginSheet (windowController.Window); return; } // Activate preview captureView.CaptureSession = captureSession; // Start running. captureSession.StartRunning (); }
public override void WindowControllerDidLoadNib(NSWindowController windowController) { base.WindowControllerDidLoadNib(windowController); // A reference to the window controller must be kept on the managed side // to keep the object from being GC'd so that the delegates below resolve. // Don't remove unless the framework is updated to track the reference. this.windowController = windowController; NSError err; windowController.Window.WillClose += delegate { if (captureSession != null) { captureSession.StopRunning(); } var dev = captureInput.Device; if (dev.IsOpen) { dev.Close(); } }; // Create a movie, and store the information in memory on an NSMutableData movie = new QTMovie(new NSMutableData(1), out err); if (movie == null) { NSAlert.WithError(err).RunModal(); return; } movieView.Movie = movie; // Find video device captureSession = new QTCaptureSession(); var device = QTCaptureDevice.GetDefaultInputDevice(QTMediaType.Video); if (!device.Open(out err)) { NSAlert.WithError(err).RunModal(); return; } // Add device input captureInput = new QTCaptureDeviceInput(device); if (!captureSession.AddInput(captureInput, out err)) { NSAlert.WithError(err).RunModal(); return; } // Create decompressor for video output, to get raw frames decompressedVideo = new QTCaptureDecompressedVideoOutput(); decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) { lock (this){ currentImage = e.VideoFrame; } }; if (!captureSession.AddOutput(decompressedVideo, out err)) { NSAlert.WithError(err).RunModal(); return; } // Activate preview captureView.CaptureSession = captureSession; // Start running. captureSession.StartRunning(); }
/* [Export("initWithCoder:")] * public QTRDocument (NSCoder coder) : base(coder) * { * }*/ public override void WindowControllerDidLoadNib(NSWindowController windowController) { NSError error; base.WindowControllerDidLoadNib(windowController); // Create session session = new QTCaptureSession(); // Attach preview to session captureView.CaptureSession = session; captureView.WillDisplayImage = (view, image) => { if (videoPreviewFilterDescription == null) { return(image); } var selectedFilter = (NSString)videoPreviewFilterDescription [filterNameKey]; var filter = CIFilter.FromName(selectedFilter); filter.SetDefaults(); filter.SetValueForKey(image, CIFilterInputKey.Image); return((CIImage)filter.ValueForKey(CIFilterOutputKey.Image)); }; // Attach outputs to session movieFileOutput = new QTCaptureMovieFileOutput(); movieFileOutput.WillStartRecording += delegate { Console.WriteLine("Will start recording"); }; movieFileOutput.DidStartRecording += delegate { Console.WriteLine("Started Recording"); }; movieFileOutput.ShouldChangeOutputFile = (output, url, connections, reason) => { // Should change the file on error Console.WriteLine(reason.LocalizedDescription); return(false); }; movieFileOutput.MustChangeOutputFile += delegate(object sender, QTCaptureFileErrorEventArgs e) { Console.WriteLine("Must change file due to error"); }; // These ones we care about, some notifications movieFileOutput.WillFinishRecording += delegate(object sender, QTCaptureFileErrorEventArgs e) { Console.WriteLine("Will finish recording"); InvokeOnMainThread(delegate { WillChangeValue("Recording"); }); }; movieFileOutput.DidFinishRecording += delegate(object sender, QTCaptureFileErrorEventArgs e) { Console.WriteLine("Recorded {0} bytes duration {1}", movieFileOutput.RecordedFileSize, movieFileOutput.RecordedDuration); DidChangeValue("Recording"); if (e.Reason != null) { NSAlert.WithError(e.Reason).BeginSheet(Window, () => {}); return; } var save = NSSavePanel.SavePanel; save.AllowedFileTypes = new string[] { "mov" }; save.CanSelectHiddenExtension = true; save.Begin(code => { NSError err2; if (code == (int)NSPanelButtonType.Ok) { NSFileManager.DefaultManager.Move(e.OutputFileURL, save.Url, out err2); } else { NSFileManager.DefaultManager.Remove(e.OutputFileURL.Path, out err2); } }); }; session.AddOutput(movieFileOutput, out error); audioPreviewOutput = new QTCaptureAudioPreviewOutput(); session.AddOutput(audioPreviewOutput, out error); if (VideoDevices.Length > 0) { SelectedVideoDevice = VideoDevices [0]; } if (AudioDevices.Length > 0) { SelectedAudioDevice = AudioDevices [0]; } session.StartRunning(); // events: devices added/removed AddObserver(QTCaptureDevice.WasConnectedNotification, DevicesDidChange); AddObserver(QTCaptureDevice.WasDisconnectedNotification, DevicesDidChange); // events: connection format changes AddObserver(QTCaptureConnection.FormatDescriptionDidChangeNotification, FormatDidChange); AddObserver(QTCaptureConnection.FormatDescriptionWillChangeNotification, FormatWillChange); AddObserver(QTCaptureDevice.AttributeDidChangeNotification, AttributeDidChange); AddObserver(QTCaptureDevice.AttributeWillChangeNotification, AttributeWillChange); }
public override void WindowControllerDidLoadNib (NSWindowController windowController) { NSError error; base.WindowControllerDidLoadNib (windowController); // Create session session = new QTCaptureSession (); // Attach preview to session captureView.CaptureSession = session; captureView.WillDisplayImage = (view, image) => { if (videoPreviewFilterDescription == null) return image; var selectedFilter = (NSString) videoPreviewFilterDescription [filterNameKey]; var filter = CIFilter.FromName (selectedFilter); filter.SetDefaults (); filter.SetValueForKey (image, CIFilterInputKey.Image); return (CIImage) filter.ValueForKey (CIFilterOutputKey.Image); }; // Attach outputs to session movieFileOutput = new QTCaptureMovieFileOutput (); movieFileOutput.WillStartRecording += delegate { Console.WriteLine ("Will start recording"); }; movieFileOutput.DidStartRecording += delegate { Console.WriteLine ("Started Recording"); }; movieFileOutput.ShouldChangeOutputFile = (output, url, connections, reason) => { // Should change the file on error Console.WriteLine (reason.LocalizedDescription); return false; }; movieFileOutput.MustChangeOutputFile += delegate(object sender, QTCaptureFileErrorEventArgs e) { Console.WriteLine ("Must change file due to error"); }; // These ones we care about, some notifications movieFileOutput.WillFinishRecording += delegate(object sender, QTCaptureFileErrorEventArgs e) { Console.WriteLine ("Will finish recording"); InvokeOnMainThread (delegate { WillChangeValue ("Recording"); }); }; movieFileOutput.DidFinishRecording += delegate(object sender, QTCaptureFileErrorEventArgs e) { Console.WriteLine ("Recorded {0} bytes duration {1}", movieFileOutput.RecordedFileSize, movieFileOutput.RecordedDuration); DidChangeValue ("Recording"); if (e.Reason != null){ NSAlert.WithError (e.Reason).BeginSheet (Window, delegate {}); return; } var save = NSSavePanel.SavePanel; save.AllowedFileTypes = new string[] {"mov"}; save.CanSelectHiddenExtension = true; save.Begin (code => { NSError err2; if (code == (int)NSPanelButtonType.Ok){ NSFileManager.DefaultManager.Move (e.OutputFileURL, save.Url, out err2); } else { NSFileManager.DefaultManager.Remove (e.OutputFileURL.Path, out err2); } }); }; session.AddOutput (movieFileOutput, out error); audioPreviewOutput = new QTCaptureAudioPreviewOutput (); session.AddOutput (audioPreviewOutput, out error); if (VideoDevices.Length > 0) SelectedVideoDevice = VideoDevices [0]; if (AudioDevices.Length > 0) SelectedAudioDevice = AudioDevices [0]; session.StartRunning (); // events: devices added/removed AddObserver (QTCaptureDevice.WasConnectedNotification, DevicesDidChange); AddObserver (QTCaptureDevice.WasDisconnectedNotification, DevicesDidChange); // events: connection format changes AddObserver (QTCaptureConnection.FormatDescriptionDidChangeNotification, FormatDidChange); AddObserver (QTCaptureConnection.FormatDescriptionWillChangeNotification, FormatWillChange); AddObserver (QTCaptureDevice.AttributeDidChangeNotification, AttributeDidChange); AddObserver (QTCaptureDevice.AttributeWillChangeNotification, AttributeWillChange); }