I have a code in C# WinForm that should be able to read the list of songs from a listBox
and then play each song with windowsMediaPlayer
(for some reasons I want to play the songs from the last item of the listBox
to the first one ) .
here is the code I'm using :
int count = listBox1.Items.Count-1;
listBox1.SelectedItem = listBox1.Items[count];
axWindowsMediaPlayer1.URL = listBox1.SelectedItem.ToString();
axWindowsMediaPlayer1.Ctlcontrols.play();
and then when playing the first song ended I wanted to change the url
like this :
private void axWindowsMediaPlayer1_PlayStateChange_1(object sender, _WMPOCXEvents_PlayStateChangeEvent e)
{
if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
if (count > 0)
{
count = count - 1;
axWindowsMediaPlayer1.URL = listBox1.Items[count].ToString();
axWindowsMediaPlayer1.Ctlcontrols.play();
}
}
}
this code will play the first song . BUT at this line axWindowsMediaPlayer1.URL = listBox1.Items[count].ToString();
I got COM Exception ERROR
and WindowsMediaPlayer control didn't play the other songs in the list .
here is the ERROR details :
System.Runtime.InteropServices.COMException was unhandled by user code
Message=Exception from HRESULT: 0xC00D1325
Source=Interop.WMPLib
ErrorCode=-1072884955
StackTrace:
at WMPLib.IWMPPlayer4.set_URL(String pbstrURL)
at AxWMPLib.AxWindowsMediaPlayer.set_URL(String value)
at Avaye_Malakooti_92.Form1.axWindowsMediaPlayer1_PlayStateChange_1(Object sender, _WMPOCXEvents_PlayStateChangeEvent e) in C:\Users\Novin Pendar\Documents\Visual Studio 2010\Projects\New folder\Avaye Malakooti 92\Avaye Malakooti 92\Form1.cs:line 459
at AxWMPLib.AxWindowsMediaPlayer.RaiseOnPlayStateChange(Object sender, _WMPOCXEvents_PlayStateChangeEvent e)
at AxWMPLib.AxWindowsMediaPlayerEventMulticaster.PlayStateChange(Int32 newState)
InnerException:
Anybody have any Idea why did I get that error or how should I solve it ? thanks for help .