I know this has been covered but I still can't quite get what I'm after.
All I want to be able to do is open the Media Player application and pass a file to it. I don't want to embedd a control at all.
Printable View
I know this has been covered but I still can't quite get what I'm after.
All I want to be able to do is open the Media Player application and pass a file to it. I don't want to embedd a control at all.
This should do it for ya. (only tested on XP SP2 with WMP 11)
The extra quotes may not be needed if there are no spaces in the path or filename, but they are needed if there is a space which is likely with media files..Code:Process.Start("wmplayer.exe", """c:\somefile.mp3""")
Thanks kleinma but I've already tried that and there is a problem with it.
The exited event doesn't always fire and the process can leave a lock on the file. It's not the most reliable thing on the planet.
I dont know why I cant just treat it like I do with Word or Excel. Reference the COM object and use the interop wrapper class to instantiate and control the application.
right click on the toolbox, and select "choose items"
In the dialog that comes up, click the COM tab and scroll down and select Windows Media Player from the list.
This will add the WMP control to your toolbox. Drag it to your form. You can set its visible property to False so it does not show up on your form.
Then you can use code like this:
This will cause an external wmplayer instance to open and play the file you specify. When you close it, the wmplayer process will exit, even if your app is still running.Code:AxWindowsMediaPlayer1.openPlayer("c:\somefile.mp3")