/// <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; } }
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; }
public void Resume() { if (_soundOut != null) { _soundOut.Resume(); } }
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(); } }
public void StartCurrentScore() { SoundOut.Resume(); IsPlaying = true; Console.WriteLine("Starting score - " + CurrentScore.TrackName); RestartIndex(); currentMusic.Position = 0; SoundOut.Play(); }
private void PlayAlarm() { if (_soundOut.PlaybackState == PlaybackState.Paused) { _soundOut.Resume(); } else { _soundOut.Play(); } }
public bool Resume() { if (_soundOut != null) { if (_soundOut.PlaybackState == CSCore.SoundOut.PlaybackState.Paused) { _soundOut.Resume(); return(true); } } return(false); }
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"); } }
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"); } }
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); } }
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; } } }
public void Resume() { isPlaying = true; wasapiOut.Resume(); AudioDelegations.StatuesChanged?.Invoke(isPlaying); }
public void Resume() { _soundOut.Resume(); }
public void UnPause() { soundOut.Resume(); }
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; } }
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; } }