⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mp3.cs

📁 C#音乐播放器源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
                    }

                }
            }

            catch
            {
                File.WriteAllText("LoadMusic.txt","");
            }
        }

        private void lab_min_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            notifyIcon1.Visible = true;
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Visible = true;
            notifyIcon1.Visible = false;
        }

        private void 显示播放器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Visible = true;
            notifyIcon1.Visible = false;
        }

        private void 关闭播放器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer3_Tick(object sender, EventArgs e)
        {
            
                if (num_ctl_banks == 1)
                {
                    lab_mp3_name.Text = getBanks(num_ctl_lab_text) + axWindowsMediaPlayer1.currentMedia.name;
                    if (num_ctl_lab_text == 5)
                    {
                        num_ctl_banks = 2;
                        return;
                    }
                    num_ctl_lab_text++;
                }

                if (num_ctl_banks == 2)
                {
                    lab_mp3_name.Text = getBanks(num_ctl_lab_text)  + axWindowsMediaPlayer1.currentMedia.name;
                    if (num_ctl_lab_text == 0)
                    {

                        num_ctl_banks = 3;
                        return;
                    }
                    num_ctl_lab_text--;
                }

                if (num_ctl_banks == 3)
                {
                    lab_mp3_name.Text = axWindowsMediaPlayer1.currentMedia.name + getBanks(num_ctl_lab_text);
                    if (num_ctl_lab_text == 5)
                    {

                        num_ctl_banks = 4;
                        return;
                    }
                    num_ctl_lab_text++;
                }

                if (num_ctl_banks == 4)
                {
                    lab_mp3_name.Text =  axWindowsMediaPlayer1.currentMedia.name + getBanks(num_ctl_lab_text);
                    if (num_ctl_lab_text == 0)
                    {

                        num_ctl_banks = 1;
                        return;
                    }
                    num_ctl_lab_text--;
                }
           
        }


        private string  getBanks(int n)
        {
            string promo = "";
            for (int i = 0; i < n; i++)
                promo += " ";

            return promo;
        }

        private void label2_Click(object sender, EventArgs e)
        {
            if (bool_is_playing == true)
            {
                lab_play.Text = "Play";
                axWindowsMediaPlayer1.Ctlcontrols.pause();
                bool_is_playing = false;
                timer2.Enabled = false;

                timer3.Enabled = false;


                progressBar1.Value = (int)axWindowsMediaPlayer1.Ctlcontrols.currentPosition;
                lab_xx_xx.Text = axWindowsMediaPlayer1.currentMedia.durationString;

            }

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "txt文件 (*.txt)|*.txt";
            ofd.FilterIndex = 1;

            if (ofd.ShowDialog() == DialogResult.OK)
            {

                if (lab_now_position.Text != "00:00"&&lab_now_position.Text!="")
                {
                    axWindowsMediaPlayer1.Ctlcontrols.play();
                    lab_mp3_name.Text = axWindowsMediaPlayer1.currentMedia.name;
                    lab_play.Text = "Paus";
                    bool_is_playing = true;
                    num_music_time = 0;
                    timer2.Enabled = true;
                    is_playing();

                    timer3.Enabled = true;


                    progressBar1.Value = (int)axWindowsMediaPlayer1.Ctlcontrols.currentPosition;
                    lab_xx_xx.Text = axWindowsMediaPlayer1.currentMedia.durationString;

                    bool_ever_played_music = true;

                }

                try
                {
                    FileInfo fi = new FileInfo(ofd.FileName);
                    File.Copy(fi.FullName,Application.StartupPath + "\\geci\\" + fi.Name);
                }
                catch
                {
                }
            }
        }


        private void getGeci_str()
        {
            FileInfo fi = new FileInfo(axWindowsMediaPlayer1.currentMedia.sourceURL);

            foreach (string gecifile in Directory.GetFiles(Application.StartupPath + "\\geci\\"))
            {
                FileInfo fi2 = new FileInfo(gecifile);

                if (fi2.Name.Substring(0, fi2.Name.Length - 4) == fi.Name.Substring(0,fi.Name.Length-4))
                {
                    str_geci = File.ReadAllLines(gecifile,Encoding.Default);
                    return;
                }

                
            }
        }


        private void getList2_add_geci()
        {
            
            try
            {
                for (int i = 0; i < str_geci.Length; i++)
                {
                    
                    int l = str_geci[i].LastIndexOf("]");
                    if (l == 9)
                    {

                        if (axWindowsMediaPlayer1.Ctlcontrols.currentPositionString == str_geci[i].Substring(l - 8, 5))
                        {
                            listBox2.Items.Add(str_geci[i].Substring(l + 1, str_geci[i].Length - l - 1));
                            listBox2.SetSelected(listBox2.Items.Count - 1, true);
                            return;
                        }
                    }
                    else
                        if (l == 19)
                        {

                            if (axWindowsMediaPlayer1.Ctlcontrols.currentPositionString == str_geci[i].Substring(l - 8, 5) || axWindowsMediaPlayer1.Ctlcontrols.currentPositionString == str_geci[i].Substring(l - 18, 5))
                            {
                                listBox2.Items.Add(str_geci[i].Substring(l + 1, str_geci[i].Length - l - 1));
                                listBox2.SetSelected(listBox2.Items.Count - 1, true);
                                return;
                            }
                        }
                        else
                            if(l==29)
                            {
                                if (axWindowsMediaPlayer1.Ctlcontrols.currentPositionString == str_geci[i].Substring(l - 8, 5) || axWindowsMediaPlayer1.Ctlcontrols.currentPositionString == str_geci[i].Substring(l - 18, 5) || axWindowsMediaPlayer1.Ctlcontrols.currentPositionString == str_geci[i].Substring(l - 28, 5))
                                {
                                    listBox2.Items.Add(str_geci[i].Substring(l + 1, str_geci[i].Length - l - 1));
                                    listBox2.SetSelected(listBox2.Items.Count - 1, true);
                                    return;
                                }
                            }

                    
                }
            }
            catch 
            {
                
            }
        }

        private void lab_can_see_geci_panel_Click(object sender, EventArgs e)
        {
            if (bool_ctl_open == false && bool_ctl_open_gecipanel == false)
            {

                pictureBox2.Visible = true;
                label2.Visible = true;
                label3.Visible = true;
                listBox2.Visible = true;

                bool_ctl_open_gecipanel = true;

                pictureBox2.Location = new Point(-3, 63);

                label2.Location = new Point(pictureBox2.Location.X + 18, pictureBox2.Location.Y + 9);
                label3.Location = new Point(pictureBox2.Location.X + 124, pictureBox2.Location.Y + 9);
                listBox2.Location = new Point(pictureBox2.Location.X + 18, pictureBox2.Location.Y + 34);


                lab_can_see_geci_panel.BackColor = Color.Thistle;
            }
            else

                if (bool_ctl_open == false && bool_ctl_open_gecipanel == true)
                {

                    pictureBox2.Visible = false;
                    label2.Visible = false;
                    label3.Visible = false;
                    listBox2.Visible = false;

                    bool_ctl_open_gecipanel = false;
                    lab_can_see_geci_panel.BackColor = Color.DarkSlateBlue;


                }

                else
                    if (bool_ctl_open == true && bool_ctl_open_gecipanel == true)
                    {

                        pictureBox2.Visible = false;
                        label2.Visible = false;
                        label3.Visible = false;
                        listBox2.Visible = false;

                        bool_ctl_open_gecipanel = false;
                        lab_can_see_geci_panel.BackColor = Color.DarkSlateBlue;

                        


  

                    }
                    else
                        if (bool_ctl_open == true && bool_ctl_open_gecipanel == false)
                        {

                            pictureBox2.Visible = true;
                            label2.Visible = true;
                            label3.Visible = true;
                            listBox2.Visible = true;

                            bool_ctl_open_gecipanel = true;
                            pictureBox2.Location = new Point(318, 0);

                            label2.Location = new Point(pictureBox2.Location.X + 18, pictureBox2.Location.Y + 9);
                            label3.Location = new Point(pictureBox2.Location.X + 124, pictureBox2.Location.Y + 9);
                            listBox2.Location = new Point(pictureBox2.Location.X + 18, pictureBox2.Location.Y + 34);

                            lab_can_see_geci_panel.BackColor = Color.Thistle;
                        }
        }

        private void btn_help_Click(object sender, EventArgs e)
        {
            MessageBox.Show("请下载完整版歌曲,否则歌词会不对应,歌词请从百度或者Yahoo下载流行的LRC带时间显示的歌词,如音乐文件为XX.mp3,则歌词文件应为XX.txt,如有宝贵意见请联系我-作者:软工佘志典QQ:337482616","MusicBaby");
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -