使用Media Element Windows 8.1 Universal app显示video播放进度

我想在播放时显示video的进展,但我没有在媒体元素上获得任何事件,我将获得video的播放进度,如下载进度和缓冲进度。 有没有其他方法可以实现它? 还是其他一些工具?

                                

上面我给了我的xaml for refrence。

一个简单的解决方案是通过Binding来完成。 这个非常简单的例子看起来像这样:

首先,我们需要转换器将TimeSpanDuration转换为double (因为ProgressBas的值使用此类型):

 public class TimeSpanToDouble : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { return (value == null) ? 0 : ((TimeSpan)value).TotalSeconds; } public object ConvertBack(object value, Type targetType, object parameter, string language) { throw new NotImplementedException(); } } public class DurationToDouble : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { return (value == null) ? 0 : ((Duration)value).TimeSpan.TotalSeconds; } public object ConvertBack(object value, Type targetType, object parameter, string language) { throw new NotImplementedException(); } } 

一旦我们拥有它,其余部分在xaml中很简单 – 只需将ProgressBar的值绑定到MediaElement 值并开始播放:

         

当然这需要一些改进,但应该帮助你开始。

另请注意,您可以使用Slider而不是ProgressBar并定义TwoWay绑定 – 在这种情况下,您不仅可以跟踪进度,还可以跳转到video的特定位置。

我建议使用播放器框架。 使用它更容易构建video播放器https://playerframework.codeplex.com/