示例#1
0
        /// <summary>
        /// Toggles the motion of the current media element.
        /// </summary>
        /// <param name="mediaData">The media data o the current element.</param>
        public void ToggleSlowMotion(MediaData mediaData)
        {
            bool result = false;

            if (mediaData != null)
            {
                CoreSmoothStreamingMediaElement mediaElement = mediaData.Media as CoreSmoothStreamingMediaElement;

                if (mediaElement != null)
                {
                    result = mediaElement.OnSlowMotion();
                }
            }
            else
            {
                if (this.HasSource)
                {
                    result = this.Player.OnSlowMotion();
                }
            }

            if (!result)
            {
                this.SlowMotionButton.IsChecked = false;
            }
        }
示例#2
0
        /// <summary>
        /// Picks a thumbnail of the current media element.
        /// </summary>
        /// <param name="mediaData">The media data o the current element.</param>
        public void PickThumbnail(MediaData mediaData)
        {
            if (mediaData != null)
            {
                SmoothStreamingMediaElement mediaElement = mediaData.Media as SmoothStreamingMediaElement;

                if (mediaElement != null)
                {
                    this.StartThumbnailBuffer();
                    bool     thumbnailSeekCompleted = false;
                    TimeSpan currentPosition        = mediaElement.Position;

                    CoreSmoothStreamingMediaElement thumbnailMediaElement = new CoreSmoothStreamingMediaElement
                    {
                        Width    = mediaElement.ActualWidth,
                        Height   = mediaElement.ActualHeight,
                        IsMuted  = true,
                        AutoPlay = false,
                        Volume   = 0,
                    };

                    DispatcherTimer thubmnailTimer = new DispatcherTimer {
                        Interval = new TimeSpan(0, 0, 0, 5)
                    };

                    thubmnailTimer.Tick += (sender, e) =>
                    {
                        if (thumbnailSeekCompleted)
                        {
                            thumbnailSeekCompleted = false;
                            thubmnailTimer.Stop();
                            WriteableBitmap writeableBitmap = new WriteableBitmap(thumbnailMediaElement, null);

                            // writeableBitmap.Render(mediaElement, null);
                            writeableBitmap.Invalidate();
                            this.Model.SetThumbnail(writeableBitmap);
                            this.PlayerContainerGrid.Children.Remove(thumbnailMediaElement);
                            thumbnailMediaElement = null;
                            thubmnailTimer        = null;
                            this.EndThumbnailBuffer();
                        }
                    };

                    thubmnailTimer.Start();

                    this.PlayerContainerGrid.Children.Add(thumbnailMediaElement);

                    thumbnailMediaElement.ManifestReady += (sender, e) => ((CoreSmoothStreamingMediaElement)sender).SelectMaxAvailableBitrateTracks("cameraAngle", "camera1");

                    thumbnailMediaElement.MediaOpened += (sender, e) =>
                    {
                        ((SmoothStreamingMediaElement)sender).Position       = currentPosition;
                        ((CoreSmoothStreamingMediaElement)sender).Visibility = Visibility.Collapsed;
                    };

                    thumbnailMediaElement.SeekCompleted        += (sender, e) => thumbnailSeekCompleted = true;
                    thumbnailMediaElement.SmoothStreamingSource = mediaElement.SmoothStreamingSource;
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayableMediaData"/> class.
        /// </summary>
        /// <param name="timelineElement">The timeline element.</param>
        public PlayableMediaData(TimelineElement timelineElement)
        {
            this.timelineElement = timelineElement;
            this.timelineElement.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == "InPosition")
                {
                    if (this.mediaElement != null && (this.mediaElement.CurrentState == SmoothStreamingMediaElementState.Paused || this.mediaElement.CurrentState == SmoothStreamingMediaElementState.Playing))
                    {
                        this.In = TimeSpan.FromSeconds(this.timelineElement.InPosition.TotalSeconds);
                    }
                }

                if (e.PropertyName == "OutPosition")
                {
                    this.Out = TimeSpan.FromSeconds(this.timelineElement.OutPosition.TotalSeconds);
                }

                if (e.PropertyName == "Volume")
                {
                    if (this.mediaElement != null)
                    {
                        this.mediaElement.Volume  = timelineElement.Volume;
                        this.mediaElement.IsMuted = this.timelineElement.Volume == 0;
                    }
                }
            };

            this.mediaElement = new CoreSmoothStreamingMediaElement
            {
                Opacity  = 0,
                Volume   = timelineElement.Volume,
                IsMuted  = this.timelineElement.Volume == 0,
                AutoPlay = false
            };

            this.mediaElement.CurrentStateChanged     += this.MediaElement_CurrentStateChanged;
            this.mediaElement.ManifestReady           += this.MediaElement_ManifestReady;
            this.mediaElement.MediaOpened             += this.MediaElement_MediaOpened;
            this.mediaElement.DownloadProgressChanged += this.MediaElement_DownloadProgressChanged;
            this.mediaElement.SeekCompleted           += this.MediaElement_SeekCompleted;

            VideoAsset videoAsset = timelineElement.Asset as VideoAsset;
            AudioAsset audioAsset = timelineElement.Asset as AudioAsset;

            if (videoAsset != null)
            {
                this.Duration = TimeSpan.FromSeconds(videoAsset.Duration.TotalSeconds);
            }
            else if (audioAsset != null)
            {
                this.Duration            = TimeSpan.FromSeconds(audioAsset.Duration);
                this.mediaElement.Width  = 0;
                this.mediaElement.Height = 0;
            }

            if (this.timelineElement.Asset.IsAdaptiveAsset)
            {
                this.mediaElement.SmoothStreamingSource = this.timelineElement.Asset.Source;
            }
            else
            {
                this.mediaElement.Source = this.timelineElement.Asset.Source;
            }

            this.Out = TimeSpan.FromSeconds(this.timelineElement.OutPosition.TotalSeconds);
        }