예제 #1
0
        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);
        }
예제 #2
0
		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);
		}
예제 #3
0
        /*	[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);
        }
예제 #4
0
		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);
		}