Approach #1. If you really need a way to stream a video from the resource, you need to create a resource stream using the resource you need. This will give you an idea:
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/98f149e9-6975-4d67-a2c7-7e5c93c8cfc2[
^],
http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx[
^].
Feeding the stream read from resource as the input of your Media Player control is difficult. The only input is URI. I could not find that a special Microsoft URL schema "res://" supported. As a general approach, you need to develop a special URI instead. You will need to use the constructor for the
System.Uri
:
Uri(SerializationInfo, StreamingContext)
. For more information, see
http://msdn.microsoft.com/en-us/library/system.uri.aspx[
^].
This approach will take some effort.
Approach #2. At the same time, I agree with Albin. You will be much better off using external files. You problem is using wrong path names. Your media files are read-only (otherwise you would not put them in your resources). You should put them with your assembly executable files. Find out where your entry assembly has a main module executable and put your media files there or in some relative position. This is how:
string exePath = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetEntryAssembly().Location);
Approach #3 — intermediate. Put media in resources, on request, read the resource as a binary stream and write into temporary file; pass the file as URL to the Media Player. Again, here you need some culture of working with paths. Use
System.IO.Path.GetTempFileName
.
I would recommend Approach #2, in agreement with Albin.
—SA