示例#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);
		}
        public void AwakeFromNib()
        {
            // Create the capture session
            this.mCaptureSession = new QTCaptureSession();

            // Connect inputs and outputs to the session
            bool success;
            NSError error;

            // Find a video device
            QTCaptureDevice videoDevice = QTCaptureDevice.DefaultInputDeviceWithMediaType(QTMedia.QTMediaTypeVideo);
            if (videoDevice != null)
            {
                success = videoDevice.Open(out error);
            }
            else
            {
                success = false;
            }

            // If a video input device can't be found or opened, try to find and open a muxed input device
            if (!success)
            {
                videoDevice = QTCaptureDevice.DefaultInputDeviceWithMediaType(QTMedia.QTMediaTypeMuxed);
            }

            if (videoDevice != null)
            {
                success = videoDevice.Open(out error);
            }
            else
            {
                success = false;
            }

            if (!success)
            {
                videoDevice = null;
                // Handle error
            }

            if (videoDevice != null)
            {
                //Add the video device to the session as a device input
                this.mCaptureVideoDeviceInput = new QTCaptureDeviceInput(videoDevice);
                success = this.mCaptureSession.AddInputError(this.mCaptureVideoDeviceInput, out error);
                if (!success)
                {
                    // Handle error
                }

                // If the video device doesn't also supply audio, add an audio device input to the session
                if (!videoDevice.HasMediaType(QTMedia.QTMediaTypeSound) && !videoDevice.HasMediaType(QTMedia.QTMediaTypeMuxed))
                {
                    QTCaptureDevice audioDevice = QTCaptureDevice.DefaultInputDeviceWithMediaType(QTMedia.QTMediaTypeSound);
                    success = audioDevice.Open(out error);

                    if (!success)
                    {
                        audioDevice = null;
                        // Handle error
                    }

                    if (audioDevice != null)
                    {
                        this.mCaptureAudioDeviceInput = new QTCaptureDeviceInput(audioDevice);

                        success = this.mCaptureSession.AddInputError(this.mCaptureAudioDeviceInput, out error);
                        if (!success)
                        {
                            // Handle error
                        }
                    }
                }

                // Create the movie file output and add it to the session
                this.mCaptureMovieFileOutput = new QTCaptureMovieFileOutput();
                success = this.mCaptureSession.AddOutputError(this.mCaptureMovieFileOutput, out error);
                if (!success)
                {
                    // Handle error
                }

                this.mCaptureMovieFileOutput.Delegate = this;

                // Set the compression for the audio/video that is recorded to the hard disk.
                foreach (QTCaptureConnection connection in this.mCaptureMovieFileOutput.Connections.GetEnumerator<QTCaptureConnection>())
                {
                    NSString mediaType = connection.MediaType;
                    QTCompressionOptions compressionOptions = null;

                    // specify the video compression options
                    // (note: a list of other valid compression types can be found in the QTCompressionOptions.h interface file)
                    if (mediaType.IsEqualToString(QTMedia.QTMediaTypeVideo))
                    {
                        // use H.264
                        compressionOptions = QTCompressionOptions.CompressionOptionsWithIdentifier("QTCompressionOptions240SizeH264Video");
                        // specify the audio compression options
                    }
                    else if (mediaType.IsEqualToString(QTMedia.QTMediaTypeSound))
                    {
                        // use AAC Audio
                        compressionOptions = QTCompressionOptions.CompressionOptionsWithIdentifier("QTCompressionOptionsHighQualityAACAudio");
                    }

                    // set the compression options for the movie file output
                    this.mCaptureMovieFileOutput.SetCompressionOptionsForConnection(compressionOptions, connection);
                }

                // Associate the capture view in the UI with the session
                this.mCaptureView.CaptureSession = this.mCaptureSession;
                this.mCaptureSession.StartRunning();
            }
        }