简体   繁体   English

WPF MediaElement将位置设置为视频结尾时冻结

[英]WPF MediaElement FREEZES when setting Position to end of video

I implemented a simple video player. 我实现了一个简单的视频播放器。 In it, there is a MediaElement and a Slider, among other things. 其中有一个MediaElement和一个Slider等。 Anyway, when I slide the slider all the way to the right and set the MediaElement.Position to the very end of the video, the video FREEZES on the last frame of the video and will not resume or respond to pause/play commands until I load a different video into the MediaElement. 无论如何,当我将滑块一直向右滑动并将MediaElement.Position设置为视频的结尾时,视频会在视频的最后一帧冻结,并且直到我恢复之前都不会继续播放或响应暂停/播放命令将其他视频加载到MediaElement中。

I put in a small hack to only change the Position value to numbers that are at least 20 milliseconds from the end of the video, and the problem went away: 我放了一个小技巧,仅将Position值更改为距离视频末尾至少20毫秒的数字,然后问题就消失了:

if ( _mediaElement.HasVideo &&
     _mediaElement.NaturalDuration.HasTimeSpan &&
     (_mediaElement.NaturalDuration.TimeSpan.TotalMilliseconds - e.NewValue) > 20)
{
     _mediaElement.Position = new TimeSpan(0, 0, 0, 0, (int) e.NewValue);
}

What I don't understand is why does the video freeze on the last frame? 我不明白为什么视频会在最后一帧冻结? Is this a bug in the MediaElement control, or is there some other way to work around this problem? 这是MediaElement控件中的错误,还是有其他方法可以解决此问题?

I found a post from 3 years ago describing what seems like the same problem, and their solution was an updated nVidia driver. 我发现3年前的一篇帖子描述了同样的问题,他们的解决方案是更新的nVidia驱动程序。 I have the most up to date nVidia driver and still have this problem. 我拥有最新的nVidia驱动程序,但仍然有此问题。 I guess the above hack works, but it seems kinda strange that the video would just lock up like that. 我猜上面的破解是可行的,但是视频会像这样锁定似乎有点奇怪。

Please, check if you have Unloaded Behavior property set to Close . 请检查是否已将“ 卸载行为”属性设置为“ Close Try setting Manual . 尝试设置Manual I think Close implies unloading the video and therefore your further actions have no effect. 我认为Close 意味着要卸载视频,因此您的进一步操作无效。

<MediaElement Source="media\numbers.wmv" Name="myMediaElement" 
 Width="450" Height="250" LoadedBehavior="Manual" UnloadedBehavior="Manual" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM