视频显示在WPF MediaElement的第一帧视频、WPF、MediaElement

2023-09-02 02:04:04 作者:街角告白

我有一个WPF应用程序与我用它来运行视频中的MediaElement。我不想让视频自动播放加载的时候,所以我设置LoadedBehavior为手动。

I have a WPF-application with a MediaElement which I use to run a video. I don't want the video to autoplay when loaded, so I set the LoadedBehavior to Manual.

<MediaElement LoadedBehavior="Manual" 
              Source="foo.wmv" 
              MediaOpened="videoElement_MediaOpened" />

不过,欲加载的时候元件来显示视频的第一帧。是否有这样做的任何神奇的方法是什么?

However; I want the element to show the first frame of the video when loaded. Is there any magic way of doing this?

推荐答案

您还需要

ScrubbingEnabled="True"

然后在加载设置事件

Then set an event on Load

Loaded="Video1_Loaded"

在Video1_Load方法中添加以下内容:

In the Video1_Load method add the following:

Video1.Play();
Video1.Pause();

无视频内容的呈现剧中方法被调用之前。所以,即使你设置的位置的第1帧,你不会得到任何数据呈现的。

None of the video content is rendered before the play method is called. So even if you set the position past the first frame you wont get any data rendered.

我觉得MediaElement.ScrubbingEnabled属性是关键。

获取或设置一个值,该值指示   是否会MediaElement的更新   为寻求操作,同时帧   暂停。这是一个依赖项属性。

Gets or sets a value that indicates whether the MediaElement will update frames for seek operations while paused. This is a dependency property.

我想没有ScrubbingEnabled同样的方法,但发现的第一帧将不会渲染。不知道这只是我使用这个硬件。其他项目rember是,MediaElement的工作,顺便当你调用播放(),你可能不实际暂停()在第一帧完全,所以你可能需要调用播放之前,以减少对数据流的数量和呼叫后重置暂停。

I tried the same approach without ScrubbingEnabled but found that the first frame wouldn't render. Not sure if it's just the hardware I am using for this. The other item to rember is that the way the MediaElement works, once you call Play() you may not actually Pause() on the first frame exactly, so you may want to reduce the volume on the stream before calling Play and reset after calling Pause.

 
精彩推荐
图片推荐