コード例 #1
0
        public static void play(string recordPath, PictureBox voiceBtn)
        {
            if (player == null)
            {
                player = new WindowsMediaPlayerClass();
                player.PlayStateChange += Player_PlayStateChange;
            }

            if (player.URL == recordPath && player.playState == WMPPlayState.wmppsPlaying)
            {
                currentVoiceBtn.Load(@"icons\voice.png");
                player.stop();
                Console.WriteLine("停止播放");
            }
            else
            {
                // 停止上一个在播放的图标
                if (currentVoiceBtn != null)
                {
                    currentVoiceBtn.Load(@"icons\voice.png");
                }

                // 开始播放新图标
                currentVoiceBtn = voiceBtn;
                currentVoiceBtn.Load(@"icons\voicePlay.gif");

                player.URL = recordPath;

                player.play();

                Console.WriteLine("开始播放" + recordPath);
            }
        }
コード例 #2
0
        /// <summary>
        /// Stops the player playing.
        /// </summary>
        /// <param name="Fade">Whether to fade or not.</param>
        /// <returns>Returns true if player stops playing</returns>
        public bool Stop(bool Fade)
        {
            try
            {
                if (PlayerState == PlayerStates.Playing)
                {
                    if (!InCrossfade && !InFade)
                    {
                        if (Fade)
                        {
                            switch (PlayingPlayer)
                            {
                            case Players.Player1:
                                StoppingPlayer = Players.Player1;
                                PlayingPlayer  = Players.NULL;
                                break;

                            case Players.Player2:
                                StoppingPlayer = Players.Player2;
                                PlayingPlayer  = Players.NULL;
                                break;
                            }
                            FadeState = FadeStates.Out;
                            StartFade();
                            return(true);
                        }
                        else
                        {
                            switch (PlayingPlayer)
                            {
                            case Players.Player1:
                                StoppingPlayer = Players.Player1;
                                PlayingPlayer  = Players.NULL;
                                Player1.stop();
                                break;

                            case Players.Player2:
                                StoppingPlayer = Players.Player2;
                                PlayingPlayer  = Players.NULL;
                                Player2.stop();
                                break;
                            }
                            PlayerState = PlayerStates.Stopped;
                            return(true);
                        }
                    }
                }
                else if (PlayerState == PlayerStates.Paused)
                {
                    switch (PlayingPlayer)
                    {
                    case Players.Player1:
                        StoppingPlayer = Players.Player1;
                        PlayingPlayer  = Players.NULL;
                        Player1.stop();
                        break;

                    case Players.Player2:
                        StoppingPlayer = Players.Player2;
                        PlayingPlayer  = Players.NULL;
                        Player2.stop();
                        break;
                    }
                    PlayerState = PlayerStates.Stopped;
                    return(true);
                }
            }
            catch (Exception ex)
            {
                OnError.Invoke(new ErrorEventArgs("Stop : " + ex.Message));
            }
            return(false);
        }