When adding more files to my playlist, it throws an out of bounds exception. It doesn't throw the exception when you load files the first time around. I think the problem is because the playlist.SelectedIndex needs a value placed into it. Any ideas?
private void mediaPlayer_PlayStateChange(object sender, AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)
{
if (e.newState == 1)
{
if (playlist.SelectedIndex < playlist.Items.Count)
{
BeginInvoke(new Action(() => {
if ((playlist.SelectedIndex + 1) < playlist.Items.Count)
{
mediaPlayer.URL = paths[playlist.SelectedIndex];
playlist.SelectedIndex++;
}
else
{
mediaPlayer.Ctlcontrols.stop();
}
}));
}
}
}
private void load_button_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
files = ofd.SafeFileNames;
paths = ofd.FileNames;
}
for (int i =0; i< files.Length; i++)
{
playlist.Items.Add(files[i]);
}
playlist.SelectedIndex = 0;
}