c#制作自动播放的mp3

     //添加播放音乐事件
        private void button4_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear(); //清空ListBox中的的所以数据
            DialogResult dr = folderBrowserDialog1.ShowDialog();
            if (dr == DialogResult.OK)
            {
                //指定目录中的所选种的文件夹
                DirectoryInfo  dir = Directory.CreateDirectory(folderBrowserDialog1.SelectedPath);
                GetAllFiles(dir);  //扫描用户选种的文件夹
            }
        }

        //扫描用户选种的文件夹
        private void GetAllFiles(DirectoryInfo dir)
        {           
            this.listBox1.Items.Clear();
            FileSystemInfo[] fileInfo =  dir.GetFileSystemInfos();  //返回指定目录文件中的所有子文件
            foreach (FileSystemInfo fileMp3 in fileInfo)
            {
                if (fileMp3 is DirectoryInfo)               
                    GetAllFiles((DirectoryInfo)fileMp3);                
                else
                {
                    string strPath = fileMp3.FullName; //获取文件的完整目录
                    string strFullMp3 = (strPath.Substring(strPath.LastIndexOf(@"/") + 1)).ToString(); //获取mp3的完整名称
                    string forMart = strFullMp3.Substring(strFullMp3.Length - 3); //获取文件的格式

                    if (forMart == "mp3")
                    {
                        this.listBox1.Items.Add(strFullMp3); //将mp3的名字添加到ListBox中

                        //添加列表
                        wc = new WindowsMediaPlayerClass();
                        mc = wc.newMedia(strPath);
                        this.axWindowsMediaPlayer1.currentPlaylist.appendItem(mc);
                    }
                }
            }
        }

       
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true && mc!=null)
                axWindowsMediaPlayer1.Ctlcontrols.play();
            else if(checkBox1.Checked == false)
                axWindowsMediaPlayer1.Ctlcontrols.stop();
            else if (mc == null && checkBox1.Checked == true)
            {
                MessageBox.Show("请添加列表", "提示!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                checkBox1.Checked = false;
            }

        }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值