Beispiel #1
0
        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();

            }
        }
Beispiel #2
0
        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;
                }));
        }