I'm trying to create a simple app to play all the .mp3 files in a folder, using Windows Media Player. To start with, I simply specify one of the files. Then I'll get into building a list of files to play.
My Visual Studio project has the following code for the single form's single button click method:
private void button1_Click(object sender, EventArgs e)
{
WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
try {
wplayer.URL = "\"C:\\Users\\blah\\B001N03GPM_(disc_1)_06_-_Funiculi_Funicula.mp3\"";
wplayer.controls.play();
}
catch (Exception ex) {
string s = "";
s = ex.Message;
}
}
The project references include the COM object
The error I get, when I click the button is
The error I get, when I click the button is
When I go to file explorer and open the file with Windows Media Player, it plays as expected. I've seen several posts about this topic and the solution seems to be per the code I've posted.
Any ideas why the error message from my app, when WMP performs flawlessly?
I've tried adding all the WMP references in the list under COM objects, but still no success.
No exception is thrown.
I'm trying to create a simple app to play all the .mp3 files in a folder, using Windows Media Player. To start with, I simply specify one of the files. Then I'll get into building a list of files to play.
My Visual Studio project has the following code for the single form's single button click method:
private void button1_Click(object sender, EventArgs e)
{
WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
try {
wplayer.URL = "\"C:\\Users\\blah\\B001N03GPM_(disc_1)_06_-_Funiculi_Funicula.mp3\"";
wplayer.controls.play();
}
catch (Exception ex) {
string s = "";
s = ex.Message;
}
}
The project references include the COM object
The error I get, when I click the button is
The error I get, when I click the button is
When I go to file explorer and open the file with Windows Media Player, it plays as expected. I've seen several posts about this topic and the solution seems to be per the code I've posted.
Any ideas why the error message from my app, when WMP performs flawlessly?
I've tried adding all the WMP references in the list under COM objects, but still no success.
No exception is thrown.
Share Improve this question edited Apr 2 at 16:18 Vadim Kotov 8,2848 gold badges50 silver badges63 bronze badges asked Mar 31 at 17:54 Cliff W EstesCliff W Estes 12 bronze badges New contributor Cliff W Estes is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.1 Answer
Reset to default 0Just remove the first and the last double quoute within the URL, you code shoud be as the following:
private void button1_Click(object sender, EventArgs e)
{
WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer();
try
{
wplayer.URL = "C:\\Users\\blah\\B001N03GPM_(disc_1)_06_-_Funiculi_Funicula.mp3";
wplayer.controls.play();
}
catch (Exception ex)
{
string s = "";
s = ex.Message;
}
}