private async Task StartPreviewAsync()

in Tools/Cam360/MainPage.xaml.cs [615:663]


        private async Task StartPreviewAsync()
        {
            _mediaPlayer = new MediaPlayer();
            _mediaPlayer.RealTimePlayback = true;
            _mediaPlayer.AutoPlay = true;
            _mediaPlayer.Source = MediaSource.CreateFromMediaFrameSource(_selectedFrameSource);
            _mediaPlayer.CommandManager.IsEnabled = false;
            PreviewElement.SetMediaPlayer(_mediaPlayer);
            _mediaPlayerProjection = _mediaPlayer.PlaybackSession.SphericalVideoProjection;

            // Set up the UI to preview the stream
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (ToggleForceSpherical.IsChecked == true)
                {
                    // force spherical projection format from UI button
                    _mediaPlayerProjection.FrameFormat = SphericalVideoFrameFormat.Equirectangular;
                    _mediaPlayerProjection.IsEnabled = true;
                    _mediaPlayerProjection.HorizontalFieldOfViewInDegrees = 120;
                    if (_sphericalProjectionEffect != null)
                    {
                        _sphericalProjectionEffect.SphericalProjection.HorizontalFieldOfViewInDegrees = 120;
                    }
                }
                else
                {
                    _mediaPlayerProjection.IsEnabled = (_mediaPlayerProjection.FrameFormat == SphericalVideoFrameFormat.Equirectangular);
                }

                // Show vertical scroll bar for zoom
                FieldOfViewControl.Visibility = _mediaPlayerProjection.IsEnabled ?
                    Visibility.Visible
                    : Visibility.Collapsed;

                PreviewElement.ManipulationMode = _mediaPlayerProjection.IsEnabled ?
                    ManipulationModes.TranslateX | ManipulationModes.TranslateY | ManipulationModes.Rotate | ManipulationModes.TranslateInertia
                    : ManipulationModes.None;

                // this check box makes sense only when spherical projection is enabled.
                ToggleRecordProjection.Visibility = _mediaPlayerProjection.IsEnabled ? 
                    Visibility.Visible 
                    : Visibility.Collapsed;

                // Prevent the device from sleeping while we run the preview
                _displayRequest.RequestActive();

                _isPreviewing = true;
            });
        }