定时音乐播放

实现效果:

  

知识运用:

  Timer组件获取系统时间  Windows Media Player组件播放音乐

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = openFileDialog1.FileName.Trim();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now.ToShortTimeString() == textBox1.Text.Trim().ToString())
            {
                this.axWindowsMediaPlayer1.URL = textBox2.Text;
                this.axWindowsMediaPlayer1.Ctlcontrols.play();
                timer1.Enabled = false;
                timer2.Interval = 1000;
                timer2.Enabled = true;
                this.Show();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            if (this.axWindowsMediaPlayer1.status != "正在播放")
            {   
                timer2.Enabled = false;
                MessageBox.Show("音乐定时播放完成 谢谢使用");
            }
        }

  

原文地址:https://www.cnblogs.com/feiyucha/p/10276422.html