方法一:
//先启动Timer
Timer timer1= new Timer();
timer1.Tick += new EventHandler(Timer_Tick);
timer1.Start();
timer1.Interval=10;
//触发事件
private void Timer_Tick(object sender, EventArgs e)
{
if ((int)MediaPlayer1.playState == 1)//表示状态为停止时
{
if (listBox1.SelectedIndex < listBox1.Items.Count - 1)
listBox1.SelectedIndex = (listBox1.SelectedIndex + 1);
else
if (listBox1.Items.Count > 0)
listBox1.SelectedIndex = 0;
//播放
PlaySong(listBox1.SelectedIndex);
}
//说明此种方法有效,但有一个bug,每次遇到mediaPlayer1.Ctcontrols.Stop()方法,自动播放下一首
方法二:这个方法比较好 自动顺序播放下一首
先设置:timer1.Interval=10; 时间间隔不宜太长
private void MediaPlayer1_StatusChange(object sender, EventArgs e)
{
if (MediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
timer1.Start();
}
private void Timer_Tick(object sender, EventArgs e)
{
timer1.Stop();
if (listBox1.SelectedIndex < listBox1.Items.Count - 1)
listBox1.SelectedIndex = (listBox1.SelectedIndex + 1);
else
if (listBox1.Items.Count > 0)
listBox1.SelectedIndex = 0;
PlaySong(listBox1.SelectedIndex + 1);
}
方法三:采用线程