WPF 媒体元素视频源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/676497/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:11:51  来源:igfitidea点击:

WPF Media Element Video Source

wpfwpf-controlswmv

提问by Murat

I try to set video source in XAML code, video doesn't play:

我尝试在 XAML 代码中设置视频源,视频不播放:

<MediaElement x:Name="bgvideo" Width="800" Height="600"Source="/Videos/BG_LOOP_BIG.wmv" />

So I try to set video source in codebehind, that doesn't play too. :

所以我尝试在代码隐藏中设置视频源,这也不能播放。:

bgvideo.Source = new Uri(@"pack://application:,,,/Videos/BG_LOOP_BIG.wmv", UriKind.Absolute);

or

或者

bgvideo.Source = new Uri(@"/Videos/BG_LOOP_BIG.wmv");

It just play when video source is absoulte:

它只在视频源绝对时播放:

bgvideo.Source = new Uri(@"C:\SomeFolder\Videos\BG_LOOP_BIG.wmv");

How can I set video source with relative source?

如何使用相对源设置视频源?

采纳答案by PaulB

This works for me. Add LoadedBehavior="Manual"

这对我有用。添加 LoadedBehavior="手册"

<MediaElement LoadedBehavior="Manual" x:Name="bgvideo" Width="800" Height="600" Source="Videos/BG_LOOP_BIG.wmv" />

Then in the code behind you need to play the media

然后在后面的代码中你需要播放媒体

bgvideo.Play()

You also need to lose the first '/' in the uri.

您还需要丢失 uri 中的第一个“/”。

hth

回答by tHien

<MediaElement x:Name="bgvideo" Width="800" Height="600"Source="Videos/BG_LOOP_BIG.wmv" />

This is also working, you just have to set the property Copy to output directory of the video file on copy if newer or copy always.

这也有效,您只需将属性 Copy 设置为复制时视频文件的输出目录(如果更新或始终复制)。

回答by Simon S?derman

Drop the first slash:

删除第一个斜杠:

:)

:)

also, as far as I know, Videos cannot be embedded into the assembly.

另外,据我所知,视频不能嵌入到程序集中。