Example #1
0
        private void PlayAudio()
        {
            PromptCommandText = "听指令";

            GlobalUser.WavePlayer?.Stop();

            try
            {
                GlobalUser.AudioFileReader = new AudioFileReader(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                                              "Resources", "P0_1.mp3"));
                //Debug.Assert(wavePlayer == null);
                GlobalUser.WavePlayer = CreateWavePlayer();
                //audioFileReader.Volume = volumeSlider1.Volume;
                GlobalUser.WavePlayer.Init(GlobalUser.AudioFileReader);
                GlobalUser.WavePlayer.PlaybackStopped += OnPlaybackStopped;
                GlobalUser.WavePlayer.Play();
                int totalTime = Convert.ToInt32(GlobalUser.AudioFileReader.TotalTime.Minutes * 60 + GlobalUser.AudioFileReader.TotalTime.Seconds);
                AudioPanelVM.SetSpeakerEnabled(totalTime);
                //TotalTime = Convert.ToInt32(GlobalUser.AudioFileReader.TotalTime.TotalSeconds);
                //_dTimer.Start();
            }
            catch (Exception e)
            {
                Log4NetHelper.Error(String.Format("Play Error {0}", e.Message));
            }
        }
Example #2
0
        void OnPlaybackStopped(object sender, StoppedEventArgs e)
        {
            //_dTimer.Stop();

            GlobalUser.WavePlayer?.Stop();

            AudioPanelVM.SetAllDisable();

            // 执行倒计时
            StartCountdown();

            // we want it to be safe to clean up input stream and playback device in the handler for PlaybackStopped

            //labelNowTime.Text = "0";
            if (e.Exception != null)
            {
                Log4NetHelper.Error(String.Format("Playback Stopped due to an error {0}", e.Exception.Message));
            }
        }