将更多文件添加到我的播放列表时,它会引发超出范围的异常。第一次加载文件时,它不会引发异常。我认为问题是因为playlist.SelectedIndex需要在其中放置一个值。有什么想法吗?
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;
}