Esempio n. 1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _endPostionBlock   = GetTemplateChild("EndPositionBlock") as TextBlock;
            _startPostionBlock = GetTemplateChild("StartPositionBlock") as TextBlock;
            _mediaSlider       = GetTemplateChild("MediaSlider") as Slider;
            _playButton        = GetTemplateChild("PlayButton") as AppBarButton;
            _playButton.Click += ((sender, args) =>
            {
                if (FrameMediaPlayer != null)
                {
                    if (FrameMediaPlayer.PlaybackSession.PlaybackState == MediaPlaybackState.Paused)
                    {
                        FrameMediaPlayer.Play();
                    }
                    else
                    {
                        if (FrameMediaPlayer.PlaybackSession.CanPause)
                        {
                            FrameMediaPlayer.Pause();
                        }
                    }
                }
            });

            //_mediaSlider.ThumbToolTipValueConverter = PositionConverter;

            RenderControl();

            BindingViewModel();

            DispatcherTimerSetup();
        }
Esempio n. 2
0
        /// <summary>
        /// 从文件构造该类
        /// </summary>
        /// <param name="mediaFile"></param>
        /// <returns></returns>
        static async Task <FrameMediaPlayer> CreateFromStorageFileAsync(IStorageFile mediaFile)
        {
            var source = MediaSource.CreateFromStorageFile(mediaFile);
            FrameMediaPlayer frameMediaPlayer = new FrameMediaPlayer(source);
            await frameMediaPlayer.CalculateFrameRateFromFileAsync(mediaFile).ConfigureAwait(false);

            return(frameMediaPlayer);
        }
Esempio n. 3
0
 private async void MediaPlayer_MediaOpened(FrameMediaPlayer sender, object args)
 {
     await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
     {
         BindingViewModel();
         MediaPlayerViewModel.LoadMediaPlayer(sender);
         System.Diagnostics.Debug.WriteLine("Media Opened");
     });
 }
Esempio n. 4
0
        private async void MediaPlayer_MediaEnded(FrameMediaPlayer sender, object args)
        {
            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                MediaPlayerViewModel.Position = MediaPlayerViewModel.Duration;
            });

            System.Diagnostics.Debug.WriteLine("Media is Ended.");
        }
Esempio n. 5
0
        private async void MediaPlayer_CurrentStateChanged(FrameMediaPlayer sender, object args)
        {
            switch (sender.PlaybackSession.PlaybackState)
            {
            case MediaPlaybackState.Playing:
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (_playButton != null)
                    {
                        _playButton.Icon = new SymbolIcon(Symbol.Pause);
                    }
                    sender.PlaybackSession.PositionChanged -= PlaybackSession_PositionChanged;
                    dispatcherTimer.Start();
                });

                break;

            case MediaPlaybackState.Paused:
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (_playButton != null)
                    {
                        _playButton.Icon = new SymbolIcon(Symbol.Play);
                    }
                    dispatcherTimer.Stop();
                    sender.PlaybackSession.PositionChanged -= PlaybackSession_PositionChanged;
                    sender.PlaybackSession.PositionChanged += PlaybackSession_PositionChanged;
                });

                break;

            case MediaPlaybackState.None:
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (_playButton != null)
                    {
                        _playButton.Icon = new SymbolIcon(Symbol.Play);
                    }
                    dispatcherTimer.Stop();
                    sender.PlaybackSession.PositionChanged -= PlaybackSession_PositionChanged;
                    sender.PlaybackSession.PositionChanged += PlaybackSession_PositionChanged;
                });

                break;
            }
        }
Esempio n. 6
0
        private static void OnMediaPlayerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var transportControl            = d as FramedMediaTransportControls;
            FrameMediaPlayer newMediaPlayer = e.NewValue as FrameMediaPlayer;
            FrameMediaPlayer oldMediaPlayer = e.OldValue as FrameMediaPlayer;

            transportControl.FrameMediaPlayer = newMediaPlayer;

            if (oldMediaPlayer != null)
            {
                transportControl.UnRegeisterMediaPlayerEvent(oldMediaPlayer);
            }

            if (newMediaPlayer != null)
            {
                transportControl.RegisterMediaPlayerEvent(newMediaPlayer);
            }
        }
Esempio n. 7
0
 private void UnRegeisterMediaPlayerEvent(FrameMediaPlayer mediaPlayer)
 {
     mediaPlayer.MediaOpened -= MediaPlayer_MediaOpened;
 }
Esempio n. 8
0
 private void RegisterMediaPlayerEvent(FrameMediaPlayer mediaPlayer)
 {
     mediaPlayer.MediaOpened         += MediaPlayer_MediaOpened;
     mediaPlayer.CurrentStateChanged += MediaPlayer_CurrentStateChanged;
     mediaPlayer.MediaEnded          += MediaPlayer_MediaEnded;
 }