private async void cmbCamera_SelectionChanged()

in Tools/Cam360/MainPage.xaml.cs [143:202]


        private async void cmbCamera_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            await CleanupCameraAsync();

            if (_mediaFrameSourceGroupList.Count == 0 || cmbCamera.SelectedIndex < 0)
            {
                return;
            }

            var requestedGroup = _mediaFrameSourceGroupList[cmbCamera.SelectedIndex];
            var capturemode = _microphoneList.Count > 0 ? StreamingCaptureMode.AudioAndVideo : StreamingCaptureMode.Video;
            // Create MediaCapture and its settings
            _mediaCapture = new MediaCapture();
            var settings = new MediaCaptureInitializationSettings
            {
                SourceGroup = requestedGroup,
                AlwaysPlaySystemShutterSound = true,
                StreamingCaptureMode = capturemode
            };

            // Initialize MediaCapture
            try
            {
                await _mediaCapture.InitializeAsync(settings);

                _selectedFrameSource = _mediaCapture.FrameSources.FirstOrDefault(source => source.Value.Info.MediaStreamType == MediaStreamType.VideoPreview 
                                                                                           && source.Value.Info.SourceKind == MediaFrameSourceKind.Color).Value;
                if (_selectedFrameSource == null)
                {
                    _selectedFrameSource = _mediaCapture.FrameSources.FirstOrDefault(source => source.Value.Info.MediaStreamType == MediaStreamType.VideoRecord 
                                                                                               && source.Value.Info.SourceKind == MediaFrameSourceKind.Color).Value;
                }

                // if no preview stream are available, bail
                if (_selectedFrameSource == null)
                {
                    throw (new Exception("could not find a VideoPreview or VideoRecord stream on the selected camera"));
                }

                _isInitialized = true;

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, 
                    () =>
                    {
                        RecordButton.IsEnabled = true;
                        PhotoButton.IsEnabled = true;
                    });
            }
            catch (Exception ex)
            {
                TraceExceptionAsync(ex);
            }

            // If initialization succeeded, start the preview
            if (_isInitialized)
            {
                // Populate UI with the available resolution and select the maximum one available
                InitializeResolutionSettings();
            }
        }