예제 #1
0
파일: Form1.cs 프로젝트: jsgydjq/train
        private void PlaySound()
        {
            string path = System.AppDomain.CurrentDomain.BaseDirectory + "music/";
            if (!System.IO.Directory.Exists(path))
            {
                return;
            }
            string[] files = System.IO.Directory.GetFiles(path, "*.mp3");
            if (files.Length > 0)
            {
                System.Random random = new Random();
                int p = random.Next(0, files.Length - 1);
                if (soundPlayer!=null)
                {
                    soundPlayer.StopT();

                }
                soundPlayer = new Mp3();
                soundPlayer.FileName = files[p];
                soundPlayer.play();

            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: jsgydjq/train
        public void StopAll()
        {
            this.Stop = true;
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPlaying)
            {
                if (this.InvokeRequired)
                {
                    this.Invoke(new Action(() =>
                        {
                            axWindowsMediaPlayer1.Ctlcontrols.stop();

                        }));
                }
                else
                {
                    axWindowsMediaPlayer1.Ctlcontrols.stop();

                }
            }
            if (soundPlayer != null)
            {
                soundPlayer.StopT();
                //soundPlayer.Dispose();
                soundPlayer = null;
            }

            if (System.Threading.Thread.CurrentThread != t)
            {
                int i = 0;
                while (i < 5000 && t.IsAlive)
                {
                    Application.DoEvents();
                    Thread.Sleep(i += 100);
                }
                if (t.IsAlive)
                {
                    t.Abort();
                }
            }
            this.Invoke(new Action(() =>
                {
                    btnQuery.Enabled = true;
                    btnStop.Enabled = false;
                }));
        }