Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 892
adhocgeek Avatar asked Dec 20 '25 17:12

adhocgeek


1 Answers

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

like image 82
Brian Dishaw Avatar answered Dec 22 '25 06:12

Brian Dishaw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!