WPF:如何播放视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22753822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF: How to play a video
提问by user255468
I tried using the standard MediaElement control to play a file, but I cannot get it to appear at all nor to play on Windows 8.1. I tried converting my file to various formats. It started as an MP4 file from the Mac, then I converted it using ffmpeg to WMV and then to MPG. None of these files would play. I am willing to convert it to an animated GIF, if there were a sure fire way to get that to play. Any help is appreciated. I am using the sample XAML code that is provided by Microsoft, and I have tried some XAML examples from StackOverflow.
我尝试使用标准 MediaElement 控件播放文件,但根本无法显示它,也无法在 Windows 8.1 上播放。我尝试将我的文件转换为各种格式。它从 Mac 开始作为 MP4 文件,然后我使用 ffmpeg 将其转换为 WMV,然后再转换为 MPG。这些文件都不会播放。我愿意将其转换为动画 GIF,如果有一种确定的方法可以播放它。任何帮助表示赞赏。我正在使用 Microsoft 提供的示例 XAML 代码,并且我尝试了 StackOverflow 中的一些 XAML 示例。
回答by UmarKashmiri
Mp4 format is supported and it should work. Try some other video. Are you using the mediaelement class?
支持 Mp4 格式,它应该可以工作。尝试一些其他视频。你在使用 mediaelement 类吗?
try this one with your videofile name
用你的视频文件名试试这个
OR
或者
Also debug to check if above events are fired.
还要调试以检查是否触发了上述事件。
If still it does not work please read this articlein detail and see what you are missing.
如果还是不行,请详细阅读这篇文章,看看你错过了什么。
回答by Max Mazur
Not sure if you had the same problem as me, but I got .mpg files and .wmv to work after some confusing problems.
不确定你是否和我有同样的问题,但在一些令人困惑的问题之后,我让 .mpg 文件和 .wmv 工作。
<MediaElement Grid.Row="0" Source="VideoElements\Wildlife.wmv" Name="myMediaElement"
Width="450" Height="250" Opacity="1" Volume="1" LoadedBehavior="Manual"
UnloadedBehavior="Stop" Stretch="Fill" />
<Image Source="images\ui_play.gif" MouseDown="OnMouseDownPlayMedia" Margin="5" />
void OnMouseDownPlayMedia(object sender, MouseButtonEventArgs args)
{
// The Play method will begin the media if it is not currently active or
// resume media if it is paused. This has no effect if the media is
// already running.
myMediaElement.Play();
}
You can try this code, and see if you can get it to work. If not i'll check if I did something else :P But remember to set your Files Build Action to "Embedded Resource" in order for this to work.
你可以试试这个代码,看看你能不能让它工作。如果没有,我会检查我是否做了其他事情 :P 但请记住将您的文件构建操作设置为“嵌入式资源”,以便使其正常工作。

