问:WMP没有随机播放列表框中的选定项目

时间:2018-05-14 07:00:36

标签: c# visual-studio wmp

嗨我正在为简单的媒体播放器工作,我的复选框出现问题而不是洗牌项目......

这是我的以下代码

ListBox1中

 private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
    {

        blumemediaplayer.Ctlcontrols.play();
        MediaFile file = listBox1.SelectedItem as MediaFile;
        if (file != null)
        {
            wmp.URL = file.Path; 
            wmp.Ctlcontrols.play();  
        }

    }

复选框用于随机播放所选项目,但是它无法正常工作

bool IsShuffle = false;
        MediaFile file = listBox1.SelectedItem as MediaFile;
        if (checkBox2.Checked==true)
        {
            if (wmp.playState == WMPPlayState.wmppsPlaying)
            {
                // do nothing in this case since song is still playing
            }
            else
            {
                if (IsShuffle)
                {                       
                    Random rand = new Random();
                    listBox1.SelectedIndex = rand.Next(0, listBox1.Items.Count - 1);
                }
                else
                {

                    if (listBox1.SelectedIndex + 1 <= listBox1.Items.Count - 1)
                    {

                     listBox1.SelectedIndex = listBox1.SelectedIndex + 1;
                    }
                    else
                    {            
                        listBox1.SelectedIndex = 0;
                    }
                }
                wmp.URL = file.Path;
            }
        }
谢谢你:)

0 个答案:

没有答案