Esempio n. 1
0
        private void PlayMusicToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //弹出内置音乐选择对话框
            SelectMusic sem = new SelectMusic();

            if (sem.ShowDialog(this) == DialogResult.OK)
            {
                NoBackMusicToolStripMenuItem.CheckState = CheckState.Unchecked;

                //如果选择了一首曲子,则播放
                try
                {
                    string music        = (string)sem.music.SelectedItem;
                    String newMusicFile = Path.Combine(Application.StartupPath, "music\\" + music);
                    if (musicFile != newMusicFile && musicFile.Length > 0)
                    {
                        MciSoundPlayer.Stop();
                        MciSoundPlayer.Close();
                    }
                    musicFile = newMusicFile;
                    MciSoundPlayer.Play(musicFile, "song");

                    NoBackMusicToolStripMenuItem.CheckState = CheckState.Unchecked;
                    PlayMusicToolStripMenuItem.CheckState   = CheckState.Checked;
                    RandomPlayToolStripMenuItem.CheckState  = CheckState.Unchecked;
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                //NoBackMusicToolStripMenuItem.CheckState = CheckState.Checked;
            }
        }
Esempio n. 2
0
 //随机播放音乐
 private void PlayRandomSongs()
 {
     try
     {
         SelectMusic sem    = new SelectMusic();
         int         count  = sem.music.Items.Count;
         Random      random = new Random();
         string      music  = (string)sem.music.Items[random.Next(count)];
         sem.Dispose();
         String newMusicFile = Path.Combine(Application.StartupPath, "music\\" + music);
         if (musicFile != newMusicFile && musicFile.Length > 0)
         {
             MciSoundPlayer.Stop();
             MciSoundPlayer.Close();
         }
         musicFile = newMusicFile;
         MciSoundPlayer.Play(musicFile, "song");
     }
     catch (Exception ex)
     {
     }
 }
Esempio n. 3
0
        //随机播放音乐
        private void PlayRandomSongs()
        {
            try
            {
                SelectMusic sem = new SelectMusic();
                int count = sem.music.Items.Count;
                Random random = new Random();
                string music = (string)sem.music.Items[random.Next(count)];
                sem.Dispose();
                String newMusicFile = Path.Combine(Application.StartupPath, "music\\" + music);
                if (musicFile != newMusicFile && musicFile.Length > 0)
                {
                    MciSoundPlayer.Stop();
                    MciSoundPlayer.Close();
                }
                musicFile = newMusicFile;
                MciSoundPlayer.Play(musicFile, "song");

            }
            catch (Exception ex)
            {

            }
        }
Esempio n. 4
0
        private void PlayMusicToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //弹出内置音乐选择对话框
            SelectMusic sem = new SelectMusic();
            if (sem.ShowDialog(this) == DialogResult.OK)
            {
                NoBackMusicToolStripMenuItem.CheckState = CheckState.Unchecked;

                //如果选择了一首曲子,则播放
                try
                {
                    string music = (string)sem.music.SelectedItem;
                    String newMusicFile = Path.Combine(Application.StartupPath, "music\\" + music);
                    if (musicFile != newMusicFile && musicFile.Length > 0)
                    {
                        MciSoundPlayer.Stop();
                        MciSoundPlayer.Close();
                    }
                    musicFile = newMusicFile;
                    MciSoundPlayer.Play(musicFile,"song");

                    NoBackMusicToolStripMenuItem.CheckState = CheckState.Unchecked;
                    PlayMusicToolStripMenuItem.CheckState = CheckState.Checked;
                    RandomPlayToolStripMenuItem.CheckState = CheckState.Unchecked;
                }
                catch (Exception ex)
                {

                }
            }
            else
            {
                //NoBackMusicToolStripMenuItem.CheckState = CheckState.Checked;

            }
        }