예제 #1
0
        /// <summary>
        ///  播放
        /// </summary>
        /// <param name="source">音频文件路径</param>
        public void Play(string source)
        {
            try
            {
                //对当前音频文件的播放状态进行判断
                if (_soundOut.PlaybackState == PlaybackState.Paused || _soundOut.PlaybackState == PlaybackState.Playing)
                //暂停或播放状态
                {
                    //继续播放
                    _soundOut.Resume();
                }
                else
                {
                    //将string 类型转换成音频文件资源
                    IWaveSource audioSource = CodecFactory.Instance.GetCodec(source);
                    //实例化音频输出

                    //初始化音频输出
                    _soundOut.Initialize(audioSource);
                    _soundOut.Volume = Volume;
                    //播放
                    _soundOut.Play();
                }
            }
            catch (Exception)
            {
                return;
            }
        }
예제 #2
0
 void Play()
 {
     if (soundOut == null || soundOut.PlaybackState == PlaybackState.Stopped)
     {
         MakeLabels(listView1.Items[now].SubItems[2].Text);
         soundSource = SoundSource(listView1.Items[now].SubItems[2].Text);
         var source = soundSource
                      .ChangeSampleRate(32000)
                      .ToSampleSource()
                      .AppendSource(Equalizer.Create10BandEqualizer, out equalizer)
                      .ToWaveSource();
         soundOut = SoundOut();
         soundOut.Initialize(source);
         float vol = tbar_volume.Value * 0.1f;
         soundOut.Volume = vol;
         soundOut.Play();
         Play_Aux();
         listView1.Items[now].BackColor = Color.SkyBlue;
         listView1.Items[now].ForeColor = Color.DarkSlateGray;
         soundOut.Stopped += Play_Aux_2;
     }
     else if (soundOut.PlaybackState == PlaybackState.Paused)
     {
         soundOut.Resume();
         timer_ctime.Enabled = true;
     }
     btn_Play.Visible  = false;
     btn_pause.Visible = true;
 }
예제 #3
0
 public void Resume()
 {
     if (_soundOut != null)
     {
         _soundOut.Resume();
     }
 }
예제 #4
0
        public void PlayAlarm(bool playAlarm = true)
        {
            if (_defaultDeviceChanged)
            {
                return;
            }
            _timerAlarmDelayArgs             = new TimerDelayArgs(DateTime.Now);
            _timerAlarmDelayArgs.alarmActive = true;
            OnUpdateTimerAlarmDelay(this, _timerAlarmDelayArgs);
            _isSoundAlertPlaying = true;
            if (!playAlarm)
            {
                return;
            }

            if (_soundOut.GetType() == typeof(WasapiOut))
            {
                if ((_soundOut as WasapiOut).Device.DeviceState != DeviceState.Active)
                {
                    GetNewSoundOut();
                }
            }

            if (_soundOut.PlaybackState == PlaybackState.Paused)
            {
                _soundOut.Resume();
            }
            else
            {
                _soundOut.Play();
            }
        }
예제 #5
0
파일: SyncrPlayer.cs 프로젝트: msf567/Syncr
 public void StartCurrentScore()
 {
     SoundOut.Resume();
     IsPlaying = true;
     Console.WriteLine("Starting score - " + CurrentScore.TrackName);
     RestartIndex();
     currentMusic.Position = 0;
     SoundOut.Play();
 }
예제 #6
0
 private void PlayAlarm()
 {
     if (_soundOut.PlaybackState == PlaybackState.Paused)
     {
         _soundOut.Resume();
     }
     else
     {
         _soundOut.Play();
     }
 }
예제 #7
0
        public bool Resume()
        {
            if (_soundOut != null)
            {
                if (_soundOut.PlaybackState == CSCore.SoundOut.PlaybackState.Paused)
                {
                    _soundOut.Resume();
                    return(true);
                }
            }

            return(false);
        }
예제 #8
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;

            Debug.WriteLine(soundOut.GetType().FullName);
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 1000);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }
예제 #9
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;

            for (int i = 0; i < basic_iteration_count; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }
예제 #10
0
        public void SoundOutBehaviour()
        {
            using (var source = new DisposableSource(GetLoopingWaveSource()))
            {
                Assert.AreEqual(PlaybackState.Stopped, _soundOut.PlaybackState);
                _soundOut.Initialize(source);
                Assert.AreEqual(PlaybackState.Stopped, _soundOut.PlaybackState);
                _soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, _soundOut.PlaybackState);
                Thread.Sleep(20);
                _soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, _soundOut.PlaybackState);
                Thread.Sleep(20);
                _soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, _soundOut.PlaybackState);
                Thread.Sleep(20);
                _soundOut.Dispose();

                Assert.IsFalse(source.IsDisposed, "{0} disposed source.", _soundOut.GetType().FullName);
            }
        }
예제 #11
0
        public override void Play()
        {
            lock (locker)
            {
                switch (soundOut.PlaybackState)
                {
                case sOut.PlaybackState.Stopped:
                    source.Position = 0;
                    soundOut.Play();
                    break;

                case sOut.PlaybackState.Paused:
                    soundOut.Resume();
                    break;

                case sOut.PlaybackState.Playing:
                    soundOut.Stop();
                    source.Position = 0;
                    soundOut.Play();
                    break;
                }
            }
        }
예제 #12
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;
            for (int i = 0; i < basic_iteration_count; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }
예제 #13
0
 public void Resume()
 {
     isPlaying = true;
     wasapiOut.Resume();
     AudioDelegations.StatuesChanged?.Invoke(isPlaying);
 }
예제 #14
0
 public void Resume()
 {
     _soundOut.Resume();
 }
예제 #15
0
 public void UnPause()
 {
     soundOut.Resume();
 }
예제 #16
0
        private void CanHandleEOFTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            int sourceLength = (int)source.GetLength().TotalMilliseconds;
            Debug.WriteLine(soundOut.GetType().FullName);
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");

                soundOut.Pause();
                soundOut.Resume();

                Thread.Sleep(10);

                soundOut.Stop();
                source.Position = 0;

                soundOut.Initialize(source);
                soundOut.Play();

                Thread.Sleep(sourceLength + 1000);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                source.Position = 0;
                soundOut.Play();

                Thread.Sleep(sourceLength + 500);
                Assert.AreEqual(source.Length, source.Position, "Source is not EOF");
            }
        }
예제 #17
0
        private void PlayPauseResumeBehaviourTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < BasicIterationCount; i++)
            {
                soundOut.Initialize(source);
                //--

                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--
                Thread.Sleep(250);
                //--
                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);
                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(10);

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                Thread.Sleep(50);

                //--
                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);
                source.Position = 0;
            }
        }
예제 #18
0
        private void PlayPauseResumeBehaviourTestInternal(ISoundOut soundOut, IWaveSource source)
        {
            for (int i = 0; i < basic_iteration_count; i++)
            {
                soundOut.Initialize(source);
                //--

                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--
                Thread.Sleep(250);
                //--
                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(50);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);
                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                soundOut.Pause();
                Assert.AreEqual(PlaybackState.Paused, soundOut.PlaybackState);

                soundOut.Resume();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);
                //--

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);

                Thread.Sleep(10);

                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);

                soundOut.Play();
                Assert.AreEqual(PlaybackState.Playing, soundOut.PlaybackState);


                //--
                soundOut.Stop();
                Assert.AreEqual(PlaybackState.Stopped, soundOut.PlaybackState);
                source.Position = 0;
            }
        }