WPF 媒体元素视频源
我尝试在 XAML 代码中设置视频源,视频无法播放:
<MediaElement x:Name="bgvideo" Width="800" Height="600"Source="/Videos/BG_LOOP_BIG.wmv" />
所以我尝试在代码隐藏中设置视频源,但也无法播放。 :
bgvideo.Source = new Uri(@"pack://application:,,,/Videos/BG_LOOP_BIG.wmv", UriKind.Absolute);
或者
bgvideo.Source = new Uri(@"/Videos/BG_LOOP_BIG.wmv");
只有在视频源为绝对源时才播放:
bgvideo.Source = new Uri(@"C:\SomeFolder\Videos\BG_LOOP_BIG.wmv");
如何使用相对源设置视频源?
I try to set video source in XAML code, video doesn't play:
<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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这也有效,您只需将属性“复制到复制时的视频文件的输出目录(如果较新)”或“始终复制”设置即可。
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.
删除第一个斜杠:
:)
另外,据我所知,视频不能嵌入到程序集中。
Drop the first slash:
:)
also, as far as I know, Videos cannot be embedded into the assembly.
这对我有用。 添加 LoadedBehavior="Manual"
然后在后面的代码中您需要播放媒体
您还需要丢失 uri 中的第一个“/”。
哈
This works for me. Add LoadedBehavior="Manual"
Then in the code behind you need to play the media
You also need to lose the first '/' in the uri.
hth