在 WPF MediaElement 中显示视频的字幕 [英] displaying subtitles for a video in a WPF MediaElement

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

问题描述

我正在开发一个 WPF 应用程序,该应用程序将视频剪辑显示为工作流程的一部分.我是通过使用 MediaElement 播放本地托管(非流式)AVI 文件来实现的.效果很好.

I'm working on a WPF application that displays video clips as part of the workflow. I'm doing this by using MediaElement to play locally hosted (not streamed) AVI files. Works great.

但是,我刚刚收到了一项新要求,允许在播放剪辑时显示字幕.我不知道解决这个问题的最佳方法.我隐约知道 WMP 可以在播放剪辑时显示单独的字幕文件,但不知道 WPF 是否支持此功能?

However, I was just handed a new requirement to allow the display of subtitles while the clip is playing. I have no idea of the best way to go about this. I'm vaguely aware that WMP has the ability to display separate subtitle files when a clip is playing, but I don't know if WPF supports this?

我可以在 WPF 中本地执行此操作吗?如果没有,我有什么选择?

Can I do this natively in WPF? If not, what are my options?

我的后备方法是要求客户将字幕直接烘焙到视频文件中,但我更愿意找到更好的方法来处理这个问题.

My fallback approach would be to require the client to bake the subtitles directly into the video file, but I'd prefer to find a better way to handle this.

推荐答案

好吧,如果您对字幕的要求只是覆盖 MediaElement 的文本,那么是的,WPF 当然可以支持这一点.您只需要将 MediaElement 与 TextBlock 一起放在 Grid 中.

Well, if your requirement for subtitles is simply text overlaying the MediaElement, then yes, WPF can certainly support this. You just need to put the MediaElement in a Grid along with a TextBlock.

真正的技巧是根据 MediaElement 中的时间更改 TextBlock Text 属性.但可能有很多方法可以做到这一点;首先想到的是使用绑定到 MediaElement.Position 属性.

The real trick will be changing the TextBlock Text property according to the time in the MediaElement. But there are probably a lot of ways to do this; the first that comes to mind is using a trigger bound to the MediaElement.Position property.

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

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