在 WPF MediaElement 中显示视频的第一帧 [英] Show first frame of video in WPF MediaElement

查看:32
本文介绍了在 WPF MediaElement 中显示视频的第一帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 MediaElement 的 WPF 应用程序,用于运行视频.我不希望视频在加载时自动播放,所以我将 LoadedBehavior 设置为 Manual.

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();

在调用 play 方法之前不会渲染任何视频内容.因此,即使您将位置设置为超过第一帧,您也不会渲染任何数据.

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 won't get any data rendered.

我认为 MediaElement.ScrubbingEnabled 属性是关键.

I think the MediaElement.ScrubbingEnabled Property is the key.

获取或设置一个值,该值指示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 的情况下尝试了相同的方法,但发现第一帧无法呈现.不确定这是否只是我为此使用的硬件.要记住的另一项是 MediaElement 的工作方式,一旦您调用 Play(),您实际上可能不会在第一帧上完全 Pause(),因此您可能想要在调用 Play() 之前降低流上的音量并在调用 Pause() 之后重置.

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 remember 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().

这篇关于在 WPF MediaElement 中显示视频的第一帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆