/// <summary> /// Fade the soundOut slowly out and disposes it after that /// </summary> /// <param name="soundOut">The sound out from CSCore</param> /// <param name="duration">The duration</param> /// <returns></returns> public async Task CrossfadeOut(ISoundOut soundOut, TimeSpan duration) { if (IsFading && !_cancellationToken.IsCancellationRequested) return; IsFading = true; await Fade(soundOut.Volume, 0, duration, soundOut, _cancellationToken.Token); IsFading = false; if (soundOut.PlaybackState != PlaybackState.Stopped) soundOut.Stop(); using (soundOut) soundOut.WaveSource.Dispose(); }
private void Stop() { timer1.Stop(); if (_soundOut != null) { _soundOut.Stop(); _soundOut.Dispose(); _soundOut = null; } if (_source != null) { _source.Dispose(); _source = null; } }
private async void Open_Click(object sender, RoutedEventArgs e) { var ofn = new OpenFileDialog { Filter = CodecFactory.SupportedFilesFilterEn }; if (ofn.ShowDialog() == true) { _soundOut.Stop(); if (_notificationSource != null) { _notificationSource.Dispose(); } var source = CodecFactory.Instance.GetCodec(ofn.FileName); //if (source.Length < 0x320000) //< 50MB if (source is MediaFoundationDecoder) { if (source.Length < 10485760) //10MB { source = new CachedSoundSource(source); } else { Stopwatch stopwatch = Stopwatch.StartNew(); source = new FileCachedSoundSource(source); stopwatch.Stop(); Debug.WriteLine(stopwatch.Elapsed.ToString()); } } source.Position = 0; await LoadWaveformsAsync(source); source.Position = 0; _sampleSource = source.ToSampleSource(); _notificationSource = new NotificationSource(_sampleSource) { Interval = 100 }; _notificationSource.BlockRead += (o, args) => { UpdatePosition(); }; _soundOut.Initialize(_notificationSource.ToWaveSource()); _soundOut.Play(); } }
/// <summary> /// Fade the soundOut slowly out and disposes it after that /// </summary> /// <param name="soundOut">The sound out from CSCore</param> /// <param name="duration">The duration</param> /// <returns></returns> public async Task CrossfadeOut(ISoundOut soundOut, TimeSpan duration) { if (IsFading && !_cancellationToken.IsCancellationRequested) { return; } IsFading = true; await Fade(soundOut.Volume, 0, duration, soundOut, _cancellationToken.Token); IsFading = false; if (soundOut.PlaybackState != PlaybackState.Stopped) { soundOut.Stop(); } using (soundOut) soundOut.WaveSource.Dispose(); }
public void Stop(bool force) { if (_soundOut != null) { _soundOut.Stop(); PlayStopped(); if (force) { _resourceItemQueue.Clear(); } } if (_waveSource != null) { _waveSource.Dispose(); _waveSource = null; } }
private void Stop() { if (_soundOut != null) { _soundOut.Stop(); _soundOut.Dispose(); _soundOut = null; } if (_soundIn != null) { _soundIn.Stop(); _soundIn.Dispose(); _soundIn = null; } if (_source != null) { _source.Dispose(); _source = null; } }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { ControlClickEvent -= ControlClickEventHandler; if (soundOut != null) { soundOut.Stop(); soundOut.Dispose(); } if (mEditor != null) { mEditor.Player.Stop(); mEditor.Dispose(); for (int i = 0; i < WiveEditorList.Count; i++) { WiveEditorList[i].Player.Stop(); WiveEditorList[i].Dispose(); } } WiveEditorList.Clear(); }
public async void FadeOut(double seconds, ISoundOut soundOut) { IsCrossfading = true; var steps = seconds / 0.2; var soundstep = soundOut.Volume / (float)steps; for (int i = 0; i < steps; i++) { if (_cancel) { _cancel = false; break; } await Task.Delay(200); try { var value = soundOut.Volume - soundstep; if (0 > value) { break; } soundOut.Volume -= soundstep; } catch (ObjectDisposedException) { IsCrossfading = false; break; } } IsCrossfading = false; if (soundOut.PlaybackState != PlaybackState.Stopped) { soundOut.Stop(); } soundOut.WaveSource.Dispose(); soundOut.Dispose(); }
public void Stop() { // Stops all the actions _Timer.Stop(); if (_soundOut != null) { _soundOut.Stop(); _soundOut.Dispose(); _soundOut = null; } if (_soundIn != null) { _soundIn.Stop(); _soundIn.Dispose(); _soundIn = null; } if (_source != null) { _source.Dispose(); _source = null; } }
public IObservable <Unit> PlayASound(string filename) { return(Observable.Create <Unit>(observer => { //Contains the sound to play IWaveSource soundSource = GetSoundSource(filename); LoopStream ls = new LoopStream(soundSource); //SoundOut implementation which plays the sound ISoundOut soundOut = GetSoundOut(); //Tell the SoundOut which sound it has to play soundOut.Initialize(ls); //Play the sound soundOut.Play(); return Disposable.Create(() => { //Stop the playback soundOut.Stop(); soundOut.Dispose(); soundSource.Dispose(); }); })); }
/// <summary> /// Stop all /// </summary> private static void Stop() { MainWindow.StopTimer(); if (m_SoundIn != null) { m_SoundIn.Stop(); m_SoundIn.Dispose(); m_SoundIn = null; } if (m_SoundOut != null) { m_SoundOut.Dispose(); m_SoundOut.Stop(); m_SoundOut = null; } if (m_Source != null) { m_Source.Dispose(); m_Source = null; } }
public bool SetAudioEndpoint(string dev, bool usedefault = false) { System.Collections.ObjectModel.ReadOnlyCollection <DirectSoundDevice> list = DirectSoundDeviceEnumerator.EnumerateDevices(); DirectSoundDevice dsd = null; if (dev != null) // active selection { dsd = list.FirstOrDefault(x => x.Description.Equals(dev)); // find if (dsd == null && !usedefault) // if not found, and don't use the default (used by constructor) { return(false); } } // seems good quality at 200 ms latency // note CS core is crap at samples around 200ms of length.. i've debugged it using audacity and they are truncated // need to find a replacement to cscore - not been updated since 2017 DirectSoundOut dso = new DirectSoundOut(200, System.Threading.ThreadPriority.Highest); if (dso == null) // if no DSO, fail.. { return(false); } if (dsd != null) { dso.Device = dsd.Guid; } else { DirectSoundDevice def = DirectSoundDevice.DefaultDevice; dso.Device = def.Guid; // use default GUID } NullWaveSource nullw = new NullWaveSource(10); try { dso.Initialize(nullw); // check it takes it.. may not if no sound devices there.. dso.Stop(); nullw.Dispose(); } catch { nullw.Dispose(); dso.Dispose(); return(false); } if (aout != null) // clean up last { aout.Stopped -= Output_Stopped; aout.Stop(); aout.Dispose(); } aout = dso; aout.Stopped += Output_Stopped; return(true); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { soundOut.Stop(); soundOut.Dispose(); }
public static void playMusic(string[] args) { try { if (!rpcInitialised) { client.Initialize(); rpcInitialised = true; } Console.Clear(); var i = 5; //initialize file and play waveSource = CodecFactory.Instance.GetCodec(MusicData.queue[0]).ToSampleSource().ToWaveSource(); soundOut = new WasapiOut() { Latency = 100 }; soundOut.Initialize(waveSource); soundOut.Play(); soundOut.Volume = MusicData.volume; //get the tags TagLib.File file = TagLib.File.Create(MusicData.queue[0]); TimeSpan time = waveSource.GetTime(waveSource.Length); var title = String.IsNullOrWhiteSpace(file.Tag.Title) ? file.Name.Split("\\")[file.Name.Split("\\").Length - 1].Split(".")[0] : file.Tag.Title; var artist = file.Tag.Performers.Length == 0 ? "N/A" : file.Tag.Performers.Length > 1 ? String.Join(", ", file.Tag.Performers) : file.Tag.Performers[0]; var album = String.IsNullOrWhiteSpace(file.Tag.Album) ? "N/A" : file.Tag.Album; Console.WriteLine("Title: " + title); Console.WriteLine("Artist: " + artist); Console.WriteLine("Album: " + album); RewriteLine(5, "Type \"help\" for a commands list"); //commands while playing while (soundOut.PlaybackState == PlaybackState.Playing || soundOut.PlaybackState == PlaybackState.Paused) { Console.SetCursorPosition(0, i); i += 2; while (true) { //get the time double ms = waveSource.Position * 1000.0 / waveSource.WaveFormat.BitsPerSample / waveSource.WaveFormat.Channels * 8 / waveSource.WaveFormat.SampleRate; TimeSpan ts = TimeSpan.FromMilliseconds(ms); setPresence(title, artist, (time.TotalMilliseconds - ms), "logo", album, soundOut.PlaybackState == PlaybackState.Playing ? "playing" : "paused"); if (Console.KeyAvailable) { var input = Console.ReadLine(); switch (input) { case "help": Console.WriteLine("Commands:"); Console.WriteLine("\"help\": Shows this menu"); Console.WriteLine("\"resume\": Resumes curent song"); Console.WriteLine("\"pause\": Pauses current song"); Console.WriteLine("\"skip\": Skips current song"); Console.WriteLine("\"volume\": View current volume or set the volume to a number from 0-100"); Console.WriteLine("\"clear\": Clears the console"); Console.WriteLine("\"stop\": Stops the application"); i += 6; break; case "resume": if (soundOut.PlaybackState != PlaybackState.Playing) { soundOut.Play(); Console.WriteLine("Unpaused \"{0}\"", file.Tag.Title); } else { Console.WriteLine("The song is already playing"); } break; case "pause": if (soundOut.PlaybackState != PlaybackState.Paused) { soundOut.Pause(); Console.WriteLine("Paused \"{0}\"", file.Tag.Title); } else { Console.WriteLine("The song is already paused"); } break; case "skip": soundOut.Stop(); CleanupPlayback(); MusicData.queue.RemoveAt(0); if (MusicData.queue.Count() >= 1) { playMusic(args); return; } else { mainProgram(args); } break; case "clear": Console.Clear(); RewriteLine(1, "Title: " + file.Tag.Title); RewriteLine(2, "Artist: " + artist); RewriteLine(3, "Album: " + file.Tag.Album); RewriteLine(4, ts.ToString(@"hh\:mm\:ss") + " \\ " + time); RewriteLine(5, "Type \"help\" for a commands list"); i = 5; Console.SetCursorPosition(0, i); break; case "stop": MusicData.queue.RemoveRange(0, MusicData.queue.Count); soundOut.Stop(); CleanupPlayback(); Main(args); break; case "volume": bool did = false; Console.WriteLine("The current volume is at {0}%", Math.Round(soundOut.Volume * 100)); Console.WriteLine("Do you want to change the volume? (y/n)"); while (!did) { var response = Console.ReadLine().ToLower(); if (response == "y") { float number; Console.WriteLine("What volume would you like to change it to?"); var value = Console.ReadLine(); bool success = float.TryParse(value, out number); if (success) { if (number > 100f || number < 0f) { Console.WriteLine("Volume must be between 0 and 100"); break; } number /= 100; soundOut.Volume = number; MusicData.volume = number; Console.WriteLine("Volume changed to {0}%", Math.Round(soundOut.Volume * 100)); } else { Console.WriteLine("\"{0}\" is not a valid number between 0 and 100", value); } did = true; break; } else if (response == "n") { did = true; break; } Console.WriteLine("Choose yes (y) or no (n)"); } break; default: Console.WriteLine("Type \"help\" for a commands list"); break; } } RewriteLine(4, ts.ToString(@"hh\:mm\:ss") + " \\ " + time.ToString(@"hh\:mm\:ss")); if (soundOut.PlaybackState == PlaybackState.Stopped) { MusicData.queue.RemoveAt(0); if (MusicData.queue.Count() >= 1) { CleanupPlayback(); playMusic(args); return; } else { mainProgram(args); } } Thread.Sleep(1000); } } } catch { Console.WriteLine("An error occured, the file that this error occured on is {0} or {1}", MusicData.queue[0], MusicData.queue.Count >= 2 ? MusicData.queue[1] : "N/A"); } }
public void stopPlaying() { soundOut.Stop(); mixer.RemoveAllSources(); }
//*********************************************************************************************************************************************************************************************************** /// <summary> /// Stop a record /// </summary> public async void StopRecord() { try { if (RecordState == RecordStates.STOPPED) { return; } if (_capture != null) { try { _capture.Stop(); _capture.Dispose(); } catch (Exception ex) { _logHandle.Report(new LogEventError("Error while stopping record: " + ex.Message)); } _silenceOut.Stop(); } if (_silenceOut != null) { _silenceOut.Stop(); _silenceOut.Dispose(); } if (_wavWriter != null) { _wavWriter.Dispose(); } _logHandle.Report(new LogEventInfo("Record (\"" + TrackInfo?.TrackName + "\") stopped.")); if (System.IO.File.Exists(FileStrWAV)) //Delete too short records { if (WasRecordPaused && RecorderRecSettings.DeletePausedRecords) { System.IO.File.Delete(FileStrWAV); DirectoryManager.DeleteEmptyFolders(RecorderRecSettings.BasePath); _logHandle.Report(new LogEventWarning("Record (\"" + TrackInfo?.TrackName + "\") deleted, because it was paused during record and DeletePausedRecords setting is enabled.")); RecordState = RecordStates.STOPPED; return; } TimeSpan wavLength = TimeSpan.Zero; try { FileInfo fileInfo = new FileInfo(FileStrWAV); if (fileInfo.Length > 44) //"Empty" files are 44 bytes big { IWaveSource wavSource = new WaveFileReader(FileStrWAV); wavLength = wavSource.GetLength(); wavSource?.Dispose(); } } catch (Exception ex) { wavLength = TimeSpan.Zero; _logHandle.Report(new LogEventError("Error while stopping record: " + ex.Message)); } if (TrackInfo?.Duration > TimeSpan.Zero && (wavLength < (TrackInfo?.Duration - AllowedDifferenceToTrackDuration) || wavLength > (TrackInfo?.Duration + AllowedDifferenceToTrackDuration))) { System.IO.File.Delete(FileStrWAV); DirectoryManager.DeleteEmptyFolders(RecorderRecSettings.BasePath); _logHandle.Report(new LogEventWarning("Record (\"" + TrackInfo?.TrackName + "\") deleted, because of wrong length (Length = " + wavLength.ToString(@"hh\:mm\:ss\.fff") + " s, Expected Range = [" + (TrackInfo?.Duration - AllowedDifferenceToTrackDuration).Value.ToString(@"hh\:mm\:ss\.fff") + ", " + (TrackInfo?.Duration + AllowedDifferenceToTrackDuration).Value.ToString(@"hh\:mm\:ss\.fff") + "]).")); RecordState = RecordStates.STOPPED; return; } } if (!System.IO.File.Exists(FileStrWAV)) { RecordState = RecordStates.STOPPED; return; } await Task.Run(() => { if (NormalizeWAVFile(FileStrWAV) == false) { RecordState = RecordStates.STOPPED; return; } _logHandle.Report(new LogEventInfo("Record (\"" + TrackInfo?.TrackName + "\") normalized.")); RecorderPostSteps?.Invoke(this, new EventArgs()); if (RecorderRecSettings.RecordFormat == RecordFormats.WAV_AND_MP3) { if (ConvertWAVToMP3(FileStrWAV, FileStrMP3) == false) { RecordState = RecordStates.STOPPED; return; } _logHandle.Report(new LogEventInfo("Record (\"" + TrackInfo?.TrackName + "\") converted to MP3.")); } else if (RecorderRecSettings.RecordFormat == RecordFormats.MP3) { if (ConvertWAVToMP3(FileStrWAV, FileStrMP3) == false) { RecordState = RecordStates.STOPPED; return; } if (System.IO.File.Exists(FileStrWAV)) { System.IO.File.Delete(FileStrWAV); } _logHandle.Report(new LogEventInfo("Record (\"" + TrackInfo?.TrackName + "\") converted to MP3 and WAV deleted.")); } AddTrackTags(FileStrWAV, TrackInfo); AddTrackTags(FileStrMP3, TrackInfo); _logHandle.Report(new LogEventInfo("Record (\"" + TrackInfo?.TrackName + "\") tagged.")); RecordState = RecordStates.STOPPED; OnRecorderPostStepsFinished?.Invoke(this, new EventArgs()); }); } catch (Exception ex) { _logHandle.Report(new LogEventError("Error while stopping record: " + ex.Message)); RecordState = RecordStates.STOPPED; } }
public void stopPlaying() { soundOut.Stop(); frequencies.Clear(); mixer.RemoveAllSources(); }
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 buttonCheck_Click(object sender, EventArgs e) { if (listViewSources.SelectedItems.Count > 0) { if (_soundIn == null) { if (SelectedDevice == null) { return; } buttonCheck.Enabled = false; if (captureMode == CaptureMode.Capture) { _soundIn = new WasapiCapture(); } else { _soundIn = new WasapiLoopbackCapture(100, new WaveFormat(48000, 24, 2)); } _soundIn.Device = SelectedDevice; _soundIn.Initialize(); var soundInSource = new SoundInSource(_soundIn) { FillWithZeros = SelectedDevice.DeviceFormat.Channels <= 1 ? true : false }; var singleBlockNotificationStream = new SingleBlockNotificationStream(soundInSource.ToStereo().ToSampleSource()); _finalSource = singleBlockNotificationStream.ToWaveSource(); singleBlockNotificationStream.SingleBlockRead += SingleBlockNotificationStreamOnSingleBlockRead; _soundIn.Start(); if (captureMode == CaptureMode.Capture) { if (SelectedDevice.DeviceFormat.Channels <= 1) { _soundOut = new WasapiOut() { Device = new MMDeviceEnumerator().GetDefaultAudioEndpoint(DataFlow.Render, Role.Communications) }; } else { _soundOut = new WasapiOut(); } _soundOut.Initialize(_finalSource); _soundOut.Play(); } else { byte[] buffer = new byte[_finalSource.WaveFormat.BytesPerSecond / 2]; soundInSource.DataAvailable += (s, ex) => { int read; while ((read = _finalSource.Read(buffer, 0, buffer.Length)) > 0) { } }; } buttonCheck.Enabled = true; buttonRefreshMicro0phone.Enabled = false; listViewSources.Enabled = false; checkBoxLoopback.Enabled = false; buttonCheck.Text = "Stop"; } else { buttonCheck.Enabled = false; if (_soundOut != null) { _soundOut.Stop(); _soundOut.Dispose(); _soundOut = null; } if (_soundIn != null) { _soundIn.Stop(); _soundIn.Dispose(); _soundIn = null; } buttonCheck.Enabled = true; listViewSources.Enabled = true; buttonRefreshMicro0phone.Enabled = true; checkBoxLoopback.Enabled = true; buttonCheck.Text = "Start"; } } else { MessageBox.Show("Reload & Select a Device"); } }
private void PlaySoundFile(object filename) { using (IWaveSource soundSource = CodecFactory.Instance.GetCodec(filename as string)) { //SoundOut implementation which plays the sound using (soundOut = GetSoundOut()) { //Tell the SoundOut which sound it has to play soundOut.Initialize(soundSource); //Play the sound soundOut.Play(); while (soundOut.PlaybackState == PlaybackState.Playing) { Thread.Sleep(500); } //Stop the playback if(soundOut.PlaybackState != PlaybackState.Stopped) soundOut.Stop(); OnPlaybackStop(this, null); } } }
private void StopHandler() { _soundOut.Stop(); _updateTimer.IsEnabled = false; PositionValue = 0; }
public void Stop() { _sound.Stop(); _sound.WaveSource.Position = 0; }
public void Stop() { Counter?.Abort(); isPlaying = false; wasapiOut.Stop(); }
private void PlaybackStoppedEventTestInternal(ISoundOut soundOut, IWaveSource source) { for (int i = 0; i < BasicIterationCount; i++) { bool raised = false; soundOut.Stopped += (s, e) => raised = true; //1. wait for the event on end of stream soundOut.Initialize(source); soundOut.Play(); Thread.Sleep((int)(source.GetLength().TotalMilliseconds + 50)); while (soundOut.PlaybackState != PlaybackState.Stopped) Thread.Sleep(10); soundOut.Initialize(source); //the playbackstate may be stopped but event was not fired. initialize will wait until it gets fired. source.Position = 0; Assert.IsTrue(raised); raised = false; //2. event on Stop() soundOut.Play(); Thread.Sleep(50); soundOut.Stop(); Assert.IsTrue(raised); } }
private void PlayStopTestInternal(ISoundOut soundOut, IWaveSource source) { for (int i = 0; i < BasicIterationCount; i++) { soundOut.Initialize(source); soundOut.Play(); soundOut.Stop(); soundOut.Initialize(source); soundOut.Play(); soundOut.Stop(); soundOut.Initialize(source); soundOut.Play(); soundOut.Stop(); soundOut.Initialize(source); soundOut.Play(); soundOut.Stop(); soundOut.Initialize(source); soundOut.Play(); soundOut.Stop(); soundOut.Initialize(source); soundOut.Play(); soundOut.Stop(); } }
public void StopBgm() { _musicOut?.Stop(); }
public async void FadeOut(double seconds, ISoundOut soundOut) { IsCrossfading = true; var steps = seconds / 0.2; var soundstep = soundOut.Volume / (float)steps; for (int i = 0; i < steps; i++) { if (_cancel) { _cancel = false; break; } await Task.Delay(200); try { var value = soundOut.Volume - soundstep; if (0 > value) break; soundOut.Volume -= soundstep; } catch (ObjectDisposedException) { IsCrossfading = false; break; } } IsCrossfading = false; if (soundOut.PlaybackState != PlaybackState.Stopped) soundOut.Stop(); soundOut.WaveSource.Dispose(); soundOut.Dispose(); }
private void Stop_Click(object sender, RoutedEventArgs e) { _soundOut.Stop(); }
public void Stop() { OutputDevice.Stop(); State = PlayerState.Paused; }
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; } }
private void StopSilence() { m_soundOut.Stop(); m_soundOut.Dispose(); }
private void CanReinitializeSoundOutTestInternal(ISoundOut soundOut, IWaveSource source) { for (int i = 0; i < BasicIterationCount; i++) { Debug.WriteLine(soundOut.ToString()); soundOut.Initialize(source); soundOut.Play(); Thread.Sleep(100); soundOut.Stop(); source.Position = 0; } }
public void Detener() //detiene una canción { _output.Stop(); _sound.SetPosition(TimeSpan.Zero); }
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; } }
/// <summary> /// 停止 /// </summary> public void Stop() { _soundOut.Stop(); //停止音频输出 }
private void VolumeResetTestInternal(ISoundOut soundOut, IWaveSource source) { soundOut.Initialize(source); soundOut.Play(); soundOut.Volume = 0.5f; Assert.AreEqual(0.5f, Math.Round(soundOut.Volume, 3)); //round => directsound may causes problems because of db => lin calculations. Thread.Sleep(50); soundOut.Stop(); soundOut.Initialize(source); soundOut.Play(); Assert.AreEqual(1.0f, soundOut.Volume); soundOut.Stop(); }
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 override void Stop() { soundOut.Stop(); }
private void StopHandler() { _soundOut.Stop(); }