I have wpf prism application with some modules. One module has folder “sounds” and mysound.wav in it, wav file has “resource” value for build action (packed in result dll). I want to play this wav file, but i can’t create valid Uri for it.
Uri(@"pack://application:,,,/MyGame;component/sounds/mysound.wav")
not working.

It says the “application” authority is for referring to content known at compile time (i.e. you have a reference to the assembly).
Because you are using Prism and the modules are loaded dynamically maybe this implies that you can’t use “application” to refer to them…(but on the other hand it could mean if an assembly is loaded into an application, then “application” can resolve to items in that assembly).
So if you mark your WAV file as “Content” instead, then the file will be loose, and you can use “siteoforigin” to access it (and maybe “application” depending on your intepretation of the microsoft link).
Make sure you set “Copy to Output Directory” set to “Copy Always” or “Copy if newer” so that the WAV file is output to your Build directory.
However, you don’t want “loose” files, so the search continues….
MediaPlayer,MediaElementandMediaTimelineonly allow the media “file” to be set via the .Source attribute …and that only takes a Uri.There isn’t any way of setting the “source” to come from a
Stream…if there was then you could have had a method in your Prism module to look up/load a sound file by name and return it as a Stream.(you may not like to hear that Silverlight can load a media object from a Stream).
Here are some other ideas for supplying the data of your WAV file that is embedded in your assembly/module to MediaElement, MediaPlayer or MediaTimeline:
Have your WAV files embedded in the module…but when you need to play them…you write the WAV content to a temporary files, and then you set up a Uri to point to that temporary file.
Try and use the Silverlight version of the MediaElement / MediaPlayer that can accept Streams, and write your module so that it uses Silverlight….there are various hacks around to host Silverlight in a WPF application….how well this would work I don’t know.
Register your own “protocol” that you can then use in a Uri.
Use WebRequest.RegisterPrefix to register your protocol prefix, and
supply it with a WebRequest factory i.e. something that implements
IWebRequestCreate.
Then create your own type of WebRequest by deriving from WebRequest
…and get that factory to return instances of it….. your
implementation would managed requesting the data from the Resource
stream….which you can access via GetResourceStream and the .Stream
property in the returned StreamResourceInfo.
Then you could use something like e.g. new
Uri(“loadwavfrom://mysound.wav”)
Perhaps use a PackageStore….add all your WAV files to the store as parts…and then get a Uri to the “Part” in that package and pass that as the .Source.
http://msdn.microsoft.com/en-us/library/3tf230ta
http://hackingsilverlight.blogspot.co.uk/2009/12/silverlight-hosting-in-wpf.html
UPDATE:
I tried RegisterPrefix and the PackageStore, and they didn’t allow it to work.
See this post:
Because MediaPlayer/MediaTimeline, etc uses Windows Media Player underneath,….when you consider Windows Media is a native app…it’s very doubtful that it can access a “Resource” from inside a .NET assembly.
So by the looks of it, it doesn’t know how to access media except via local or HTTP based Uris.
When you use an “application” pack URI that points to a “Content” file, this must get mapped to a local file URL when given to the Media Player underneath.
So the possible workaround I can think of are:
keep the WAV files as “Resource”…but write out the data to temporary files as needed…and supply that temporary file as the Uri.
put the WAV files in your project as “Content”…and supply the right Uri to that file
write your own basic local HTTP server/or use IIS and “host” the WAV files … you can then use a HTTP based Url which to access the file. (a lot of hassle I know).
use a different media player control….one that either supports accessing a Resource in a .NET assembly….or allows you to provide a proxy where you supply the data to the player. You could look at http://vlcdotnet.codeplex.com/