private void Player_MediaOpened(MediaPlayer sender, object args)
    {
        _projection = _player.PlaybackSession.SphericalVideoProjection;
        SphericalVideoFrameFormat videoFormat = _projection.FrameFormat;

        if (videoFormat != SphericalVideoFrameFormat.Equirectangular)
        {
            _projection.FrameFormat = SphericalVideoFrameFormat.Equirectangular;
        }
        _projection.IsEnabled = true;
        _projection.HorizontalFieldOfViewInDegrees    = 120;
        _player.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Start previewing
        /// </summary>
        /// <returns></returns>
        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;
            });
        }
Ejemplo n.º 3
0
        private void MediaPlayer_MediaOpened(MediaPlayer sender, object args)
        {
            videoProjection = mediaPlayer.PlaybackSession.SphericalVideoProjection;
            Windows.Media.MediaProperties.SphericalVideoFrameFormat videoFormat = videoProjection.FrameFormat;
            // Some times Content metadata doesn't provided correct format. Try to force the equirectangular format, if doesn't match
            if (videoFormat != Windows.Media.MediaProperties.SphericalVideoFrameFormat.Equirectangular)
            {
                videoProjection.FrameFormat = Windows.Media.MediaProperties.SphericalVideoFrameFormat.Equirectangular;
            }
            videoProjection.IsEnabled = true;
            videoProjection.HorizontalFieldOfViewInDegrees    = 120;
            mediaPlayer.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;

            StartInputLoop();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Stop previewing
 /// </summary>
 /// <returns></returns>
 private async Task StopPreviewAsync()
 {
     try
     {
         _mediaPlayerProjection = null;
         _mediaPlayer           = null;
         _isPreviewing          = false;
     }
     catch (Exception ex)
     {
         TraceExceptionAsync(ex);
     }
     finally
     {
         await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { RecordButton.IsEnabled = false; PhotoButton.IsEnabled = false; });
     }
 }