Beispiel #1
0
        public static async Task <IEnumerable <string> > GetAvailableCameraNamesAsync()
        {
            DeviceInformationCollection deviceInfo = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            return(deviceInfo.OrderBy(d => d.Name).Select(d => d.Name));
        }
        //This is taken right out of Essential Video Recorder, it records streaming video
        //and was the first video app I made.  This one is different in that it takes frames
        //and then renders them together.  EVR recorded straight video.

        private async void InitCamera()

        {
            stopCapture.Visibility = Visibility.Collapsed;
            var videosLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Videos);

            captureFolder = videosLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder;


            DeviceInformationCollection j = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);



            var z = j.Count();

            var Oz = j.OrderBy(x => x.Name);

            if (j.Count == 0)             //messagebox in all languages, no device.
            {
                NoCamera.Visibility = Visibility.Visible;
                return;
            }

            try
            {
                string[] dups           = new string[j.Count];
                int      WhichDevice    = 0;
                string   nameThatCamera = "";
                int      howManyCameras = 0;
                foreach (DeviceInformation q in Oz)
                {
                    nameThatCamera = q.Name;
                    if (WhichDevice > 0)
                    {
                        for (int v = 0; v < WhichDevice; v++)
                        {
                            if (nameThatCamera == dups[v])
                            {
                                howManyCameras++;
                            }
                        }
                        if (howManyCameras == 0)
                        {
                        }
                        else
                        {
                            howManyCameras++;
                            nameThatCamera = nameThatCamera + '-' + howManyCameras.ToString();
                        }
                        howManyCameras = 0;
                    }
                    dups[WhichDevice] = q.Name;
                    WhichDevice++;
                    ComboBoxItem comboBoxItem = new ComboBoxItem();
                    comboBoxItem.Content = nameThatCamera;

                    comboBoxItem.Tag = q;
                    CameraSource.Items.Add(comboBoxItem);
                }
            }
            catch (Exception e)
            {
                BadDevice.Visibility = Visibility.Visible;
            }

            try
            {
                DeviceInformation gotCamera = (DeviceInformation)Oz.First();
                MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
                settings.VideoDeviceId = gotCamera.Id;
                _mediaCapture          = new MediaCapture();

                await _mediaCapture.InitializeAsync();

                _mediaCapture.Failed += _mediaCapture_Failed;

                _mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded;


                GetTheVideo.Source = _mediaCapture;

                CheckIfStreamsAreIdentical();

                MediaStreamType streamType;

                streamType = MediaStreamType.VideoRecord;
                PopulateStreamPropertiesUI(streamType, CameraSettings2);

                //added to camera and settings initial setting
                CameraSource.SelectedIndex    = 0;
                CameraSettings2.SelectedIndex = 0;
            }
            catch (Exception e)
            {
                BadSetting.Visibility = Visibility.Visible;
            }
        }