wpf C# MediaElement Video ,如何从资源中添加视频?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17474750/
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
C# MediaElement Video , how to add video from resources?
提问by Superzarzar
i have the MediaElement and i want to play a video, as i know the only way of doing so is to set this item Source
我有 MediaElement,我想播放视频,因为我知道这样做的唯一方法是设置此项目 Source
mediaElement1.Source = new Uri(fileName);
but now i have the resources file which i wanna play but i cant do so because it doesnt have a path. so to make a long story short, i'm looking for a way to play video in the madiaElement from the resources file(without writing its byte first).
但现在我有我想播放的资源文件,但我不能这样做,因为它没有路径。所以长话短说,我正在寻找一种方法来从资源文件中播放 madiaElement 中的视频(而不是先写字节)。
回答by ridoy
From first line in the "Remarks"section of the MediaElementdocs: "When distributing media with your application, you cannot use a media file as a project resource. In your project file, you must instead set the media type to Content and set CopyToOutputDirectory to PreserveNewest or Always."
So you can't play video from a resource. You can play a file attached to a project as content.
Some alternate ways described here..
从MediaElement文档“备注”部分的第一行开始:“使用您的应用程序分发媒体时,您不能将媒体文件用作项目资源。在您的项目文件中,您必须将媒体类型设置为 Content 并设置 CopyToOutputDirectory保留最新或始终。” 所以你不能从资源播放视频。您可以将附加到项目的文件作为内容播放。
这里描述的一些替代方法..

