Beispiel #1
0
        /*******************************************************************************************
        * PUBLIC METHODS
        *******************************************************************************************/
        public async Task Initialize()
        {
            //Initialize Camera
            if (mediaCapture == null)
            {
                // Attempt to get the back camera if one is available, but use any camera device if not
                var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Back);

                if (cameraDevice == null)
                {
                    Debug.WriteLine("No camera device found!");
                    return;
                }

                // Create MediaCapture and its settings
                mediaCapture = new MediaCapture();

                var settings = new MediaCaptureInitializationSettings {
                    VideoDeviceId = cameraDevice.Id
                };
                // Initialize MediaCapture
                try
                {
                    await mediaCapture.InitializeAsync(settings);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Debug.WriteLine("The app was denied access to the camera. Ensure webcam capability is added in the manifest.");

                    // Log telemetry event about this exception
                    var events = new Dictionary <string, string> {
                        { "UsbCamera", ex.Message }
                    };
                    App.Controller.TelemetryClient.TrackEvent("FailedToInitializeMediaCapture", events);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Exception when initializing MediaCapture with {0}: {1}", cameraDevice.Id, ex.ToString()));

                    // Log telemetry event about this exception
                    var events = new Dictionary <string, string> {
                        { "UsbCamera", ex.Message }
                    };
                    App.Controller.TelemetryClient.TrackEvent("FailedToInitializeMediaCapture", events);
                }
            }

            //Initialize PIR Sensor
            pirSensor            = new MotionSensor();
            pirSensor.OnChanged += PirSensor_OnChanged;

            this.isEnabled = true;
        }
        /*******************************************************************************************
        * PUBLIC METHODS
        *******************************************************************************************/
        public async Task Initialize()
        {
            //Initialize Camera
            if (mediaCapture == null)
            {
                // Attempt to get the back camera if one is available, but use any camera device if not
                var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Back);

                if (cameraDevice == null)
                {
                    Debug.WriteLine("No camera device found!");
                    return;
                }

                // Create MediaCapture and its settings
                mediaCapture = new MediaCapture();

                var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id };
                // Initialize MediaCapture
                try
                {
                    await mediaCapture.InitializeAsync(settings);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Debug.WriteLine("The app was denied access to the camera. Ensure webcam capability is added in the manifest.");

                    // Log telemetry event about this exception
                    var events = new Dictionary<string, string> { { "UsbCamera", ex.Message } };
                    App.Controller.TelemetryClient.TrackEvent("FailedToInitializeMediaCapture", events);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Exception when initializing MediaCapture with {0}: {1}", cameraDevice.Id, ex.ToString()));

                    // Log telemetry event about this exception
                    var events = new Dictionary<string, string> { { "UsbCamera", ex.Message } };
                    App.Controller.TelemetryClient.TrackEvent("FailedToInitializeMediaCapture", events);
                }
            }

            //Initialize PIR Sensor
            pirSensor = new MotionSensor();
            pirSensor.OnChanged += PirSensor_OnChanged;
        }