public void Pause() { if (this.IsPlaying && waveOut != null) { waveOut.Pause(); } }
public void Pause() { if (_waveOut.PlaybackState == PlaybackState.Playing) { _waveOut.Pause(); } }
internal static void Main(string[] args) { // Create a SID reader. sid = new SidReader("Tests/2short1s.sid", 44100, 2, SidModel.MOS8580, SidClock.NTSC); // Initialize the player and start. IWavePlayer player = new WaveOut(); player.Init(sid); // Initialize track count track = sid.CurrentSong; // Display the initial track information. DisplayTrackInfo(); // Loop to check if the user hits left or right arrow keys to change tracks. ConsoleKeyInfo keyInfo; do { keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.LeftArrow) { if (track > 1) { track--; sid.SetTune(track); DisplayTrackInfo(); } } else if (keyInfo.Key == ConsoleKey.RightArrow) { if (track != sid.NumberOfSubtunes) { track++; sid.SetTune(track); DisplayTrackInfo(); } } else if (keyInfo.Key == ConsoleKey.Spacebar) { if (isPlaying) { player.Pause(); isPlaying = false; } else { player.Play(); isPlaying = true; } } } while (keyInfo.Key != ConsoleKey.Escape && keyInfo.Key != ConsoleKey.Enter); }
private static void Main(string[] args) { // Initialization Console.OutputEncoding = Encoding.UTF8; var ape = new ApeReader(args[0]); DisplayInformation(ape.Handle); // Set up the player. IWavePlayer player = new WaveOut(); player.Init(ape); player.Play(); // Listen for key presses to pause/play audio. var isPlaying = true; do { var keyInfo = Console.ReadKey(); if (keyInfo.Key == ConsoleKey.Spacebar) { if (isPlaying) { player.Pause(); isPlaying = false; } else { player.Play(); isPlaying = true; } } // If we hit the end of the stream in terms of actual audio data. if (isPlaying && ape.Position == ape.Length) { player.Stop(); } } while (player.PlaybackState != PlaybackState.Stopped); }
private void StartPlayingThisClip(AudioClipToPlay clip, double curSec) { cxzxc(string.Format("start of {0} {1}-{2}", clip.Filename, clip.SecFileStart, clip.SecFileEnd)); // create the device IWavePlayer waveOutDevice = new WaveOut(); var deviceAndShit = new DeviceAndItsData(waveOutDevice, clip); lock (this) { devicesPlaying.Add(deviceAndShit); } Thread ttt = new Thread(() => { using (var reader = OpenAudioFile(clip.Filename)) { deviceAndShit.WaveReader = reader; // init the playback stuff waveOutDevice.Init(reader); var syncOffsetSec = curSec - clip.SecOffset; // would be 0 if curSec == clip.SecOffset var clipSecStart = clip.SecFileStart + syncOffsetSec; var clipSecEnd = clip.SecFileEnd; reader.CurrentTime = TimeSpan.FromSeconds(clipSecStart + NAUDIO_SYNC_OFFSET); var endTs = TimeSpan.FromSeconds(clipSecEnd + NAUDIO_SYNC_OFFSET); var sleepTs = TimeSpan.FromSeconds(NAUDIO_SLEEP_FRAME_TIME); deviceAndShit.PlaybackStateRequest = PlaybackState.Playing; waveOutDevice.Play(); while (reader.CurrentTime < endTs) { Thread.Sleep(sleepTs); if (waveOutDevice.PlaybackState == PlaybackState.Playing && deviceAndShit.PlaybackStateRequest == PlaybackState.Paused) waveOutDevice.Pause(); if (waveOutDevice.PlaybackState == PlaybackState.Paused && deviceAndShit.PlaybackStateRequest == PlaybackState.Playing) waveOutDevice.Play(); if (deviceAndShit.StopHasBeenInvoked) break; if (waveOutDevice.PlaybackState == PlaybackState.Stopped) break; } waveOutDevice.Stop(); // no harm calling stop 2x right? lock (this) { devicesPlaying.Remove(deviceAndShit); devicesPaused.Remove(deviceAndShit); } cxzxc(string.Format("stop of {0} {1}-{2}", clip.Filename, clip.SecFileStart, clip.SecFileEnd)); } }); ttt.Start(); }
private void button26_Click(object sender, EventArgs e) { if (pausePlay && output != null && output.PlaybackState == NAudio.Wave.PlaybackState.Playing) { output.Pause(); if (outputLocal != null && outputLocal.PlaybackState == NAudio.Wave.PlaybackState.Playing) { outputLocal.Pause(); } foreach (KeyValuePair <Stopwatch, string> time in stopwatches) { long timeE = time.Key.ElapsedMilliseconds; time.Key.Stop(); long pLMil = timeE; int pMil = Convert.ToInt32(pLMil); string min = ((pMil / 1000) / 60).ToString(); string sec = ((pMil / 1000) % 60).ToString(); string mil = (pMil % 1000).ToString(); if (min.Length < 2) { min = "0" + min; } if (sec.Length < 2) { sec = "0" + sec; } if (mil.Length < 2) { mil = "00" + mil; } else if (mil.Length < 3) { mil = "0" + mil; } textBox9.Text = "Paused At " + min + ":" + sec + ":" + mil; /* + " out of " + + ((totalMil / 1000) / 60).ToString().Substring(0, ((totalMil / 1000) / 60).ToString().IndexOf('.')) + ":" + ((totalMil / 1000) % 60).ToString() + ":" + (totalMil % 1000).ToString(); */ } // seconds: totalMil / 1000, mil: totalMil % 1000, (totalMil / 1000) / 60 pausePlay = false; } else if (!pausePlay && output != null && output.PlaybackState == PlaybackState.Paused) { output.Play(); if (outputLocal != null && outputLocal.PlaybackState == NAudio.Wave.PlaybackState.Paused) { outputLocal.Play(); } foreach (KeyValuePair <Stopwatch, string> time in stopwatches) { time.Key.Start(); } string upTime = textBox9.Text.Substring(10); textBox9.Text = "Unpaused At " + upTime; pausePlay = true; } }
/// <summary> /// Sets on pause /// </summary> public void pause() { output.Pause(); }