From 0c9a368a5ab04ddb16826056b18c49ba1944980a Mon Sep 17 00:00:00 2001 From: Jay Sim Date: Fri, 14 Jul 2017 13:38:15 +1000 Subject: [PATCH] fix an issue that bufferingchanged event never been fired on UWP --- MediaManager.UWP/AudioPlayerImplementation.cs | 11 +++++++++++ Samples/Simple/MediaSample.UWP/MainPage.xaml.cs | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/MediaManager.UWP/AudioPlayerImplementation.cs b/MediaManager.UWP/AudioPlayerImplementation.cs index 579bcd1a..ef660e56 100644 --- a/MediaManager.UWP/AudioPlayerImplementation.cs +++ b/MediaManager.UWP/AudioPlayerImplementation.cs @@ -79,8 +79,19 @@ public AudioPlayerImplementation(IVolumeManager volumeManager) }; _player.MediaEnded += (sender, args) => { MediaFinished?.Invoke(this, new MediaFinishedEventArgs(_currentMediaFile)); }; + + _player.PlaybackSession.BufferingStarted += (sender, args) => + { + var bufferedTime = + TimeSpan.FromSeconds(sender.BufferingProgress * + sender.NaturalDuration.TotalSeconds); + BufferingChanged?.Invoke(this, + new BufferingChangedEventArgs(sender.BufferingProgress, bufferedTime)); + }; + _player.PlaybackSession.BufferingProgressChanged += (sender, args) => { + //This seems not to be fired at all var bufferedTime = TimeSpan.FromSeconds(_player.PlaybackSession.BufferingProgress* _player.PlaybackSession.NaturalDuration.TotalSeconds); diff --git a/Samples/Simple/MediaSample.UWP/MainPage.xaml.cs b/Samples/Simple/MediaSample.UWP/MainPage.xaml.cs index 15cf3978..dedb79b6 100644 --- a/Samples/Simple/MediaSample.UWP/MainPage.xaml.cs +++ b/Samples/Simple/MediaSample.UWP/MainPage.xaml.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using Windows.ApplicationModel.Core; using Windows.UI.Core; using Windows.UI.Xaml; @@ -22,11 +23,19 @@ public MainPage() { InitializeComponent(); CrossMediaManager.Current.PlayingChanged += OnPlayingChanged; + CrossMediaManager.Current.BufferingChanged += OnBufferingChanged; CrossMediaManager.Current.StatusChanged += OnStatusChanged; CrossMediaManager.Current.VideoPlayer.RenderSurface = VideoCanvas; CrossMediaManager.Current.MediaFileChanged += CurrentOnMediaFileChanged; } + private void OnBufferingChanged(object sender, BufferingChangedEventArgs bufferingChangedEventArgs) + { + var bufferingProgress = bufferingChangedEventArgs?.BufferProgress ?? 0; + var bufferingTime = bufferingChangedEventArgs?.BufferedTime; + Debug.WriteLine($"buffering progress: {bufferingProgress}, buffering time: {bufferingTime}"); + } + private void CurrentOnMediaFileChanged(object sender, MediaFileChangedEventArgs mediaFileChangedEventArgs) { var mediaFile = mediaFileChangedEventArgs.File;