Skip to content

Commit

Permalink
fix an issue that bufferingchanged event never been fired on UWP
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay Sim committed Jul 14, 2017
1 parent d2ee1b8 commit 0c9a368
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions MediaManager.UWP/AudioPlayerImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions Samples/Simple/MediaSample.UWP/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
using Windows.UI.Xaml;
Expand All @@ -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;
Expand Down

0 comments on commit 0c9a368

Please sign in to comment.