I have a wmp component in a C# Windows Forms and i want it to play a video (.avi) from the solution's resources. I need to know the code for the wmp component to find the video. Suggestions?
Asked
Active
Viewed 2,494 times
0
-
Here come the downvotes... – Brian Jul 01 '13 at 17:29
-
What did you so far? Post some Code. – Smartis has left SO again Jul 01 '13 at 17:29
-
1@Brian always the same -.- – Smartis has left SO again Jul 01 '13 at 17:29
-
Don't forget to add `using WMPLib;` – Jonas Jun 07 '19 at 23:43
1 Answers
3
Currently there is a way over streaming the file.
First of all, we need a place where it should be always possible
string streamPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\";
Next Step an Instance of the MediaPlayer
WindowsMediaPlayer wmp = new WindowsMediaPlayer();
Then we need to stream the Assembly Resource
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Smartis.Resources.Natur.wmv");
using (Stream output = new FileStream (streamPath + "mediafile.avi", FileMode.Create))
{
byte[] buffer = new byte[32*1024];
int read;
while ( (read= stream.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
}
Finally we should be able to load the file.
wmp.URL = streamPath + "mediafile.avi";
wmp.controls.play();
After playing don't forget to clear the folder:
File.Delete(streamPath + "mediafile.avi");

Smartis has left SO again
- 5,025
- 4
- 31
- 45
-
This won't work because the video is not located in an URL, it's in the resources of the program – Lucas Dias Jul 01 '13 at 17:53
-
1Gentlemen, you had my curiosity. But now you have my attention. Upvote – Smartis has left SO again Jul 01 '13 at 18:00