在C#中逐个播放组合框中的歌曲列表

时间:2015-02-24 07:39:29

标签: c# combobox

我有一个组合框中的歌曲列表。如果是用户,我正根据选择播放歌曲。这是我的代码。

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        wplayer.controls.pause();
        song = comboBox1.SelectedItem.ToString();
        index1 = comboBox1.SelectedIndex;
        pictureBox4.Image=Image.FromFile(Application.StartupPath + "\\Input\\zeneszek.gif");
        pictureBox4.SizeMode=PictureBoxSizeMode.StretchImage;
        pictureBox4.Visible=true;
         wplayer.PlayStateChange += new WMPLib._WMPOCXEvents_PlayStateChangeEventHandler(wplayer_PlayStateChange);
        wplayer.URL = Application.StartupPath + "\\Input\\" + song + ".mp3";
        wplayer.controls.play();
        WMPLib.WMPPlayState playstate = WMPLib.WMPPlayState.wmppsMediaEnded;
        label4.Text = "Playing" + song;
    }
 public void wplayer_PlayStateChange(int newstate)
        {
            if (newstate == (int)WMPLib.WMPPlayState.wmppsMediaEnded)
            {
                playstate = WMPLib.WMPPlayState.wmppsMediaEnded;
                song = comboBox1.Items[index1++].ToString();
}
}

在歌曲结束后,我想播放下一首歌曲,这是组合框选择中的下一首歌曲。有人可以帮忙吗?我也试过了playstate change事件。我仍然无法播放下一首歌。当播放状态为wmppsMediaEnded时,我增加了组合框的索引。我什么时候需要播放那首歌?当状态为wmppsStopped和wmmppsTransitioning时,我尝试播放这首歌,但在这两种情况下,我只能连续播放两首歌曲。在第二首歌结束后,我无法播放剩余的歌曲。

1 个答案:

答案 0 :(得分:1)

使用PlayStateChangeEvent检查显示媒体已结束的newstate,然后移动selectedindex + 1并播放新歌。

https://msdn.microsoft.com/en-us/library/windows/desktop/dd564079%28v=vs.85%29.aspx

这也可能对您有所帮助:http://stereoclood.codeplex.com/SourceControl/latest#SteroMood/MediaPlayers/WmpMediaPlayer.cs