How would I use a pack uri resource with media player?

时间秒杀一切 提交于 2019-12-22 17:36:19

问题


I have some very simple code which just needs to play a sound with a specified volume, as follows :

var mp = new MediaPlayer();
mp.Open(uri);
mp.Volume = volume;
mp.Play();

The problem arises because this is part of a Prism module. I don't know where the executing assembly is going to be so I can't use a relative Uri or siteoforigin and MediaPlayer doesn't understand the pack Uri syntax.

I have a resource wav file at the root of my assembly called "notify.wav", but I have no way to pass it into MediaPlayer via a Uri and can't see any other way to load it.

How do I play the file?


回答1:


Since the resource is embedded and the MediaPlayer doesn't support pack uri, you'll need to read the resource in as a stream and write it out to file.You should then be able to load the file into the player as necessary.

I would write the file to my applications directory so that once extracted from the assembly, you can just reference the file directly.

Hope this helps




回答2:


First you should declare a variable that is string for your media folder's path. This variable holds the path. just like:

string url = @"C:\Users\Alico\Documents\visual studio 2010\Projects\WpfBrushesTest\WpfBrushesTest\Dido - Thank You.mp4";

and then

mp.Open(new Uri(url,UriKind.Relative));



回答3:


I’m afraid Media player does not support pack URI.

Have you tried Directory.GetCurrentDirectory or Environment.CurrentDirectory?



来源:https://stackoverflow.com/questions/3728181/how-would-i-use-a-pack-uri-resource-with-media-player

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!