首页 > 解决方案 > Q : WMP 不随机播放基于列表框的选定项目

问题描述

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

这是我的以下代码

列表框1

 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;
            }
        }

谢谢你 :)

标签: c#visual-studiowmp

解决方案


推荐阅读