/// <summary> /// Plays the currently selected track. /// </summary> /// <param name="reset">Whether the track should be reset to initial position or not.</param> public void Play(bool reset = false) { if (reset) { CurrentStream.Position = 0; } CurrentOut.Play(); }
/// <summary> /// Plays a given track. If the track is already playing, the player carries on. /// </summary> /// <param name="stream">The track to play.</param> /// <param name="reset">Whether the track should be reset to initial position or not.</param> public void Play(WaveStream stream, bool reset = false) { Select(stream); if (reset) { CurrentStream.Position = 0; } CurrentOut.Play(); }
/// <summary> /// Plays a track created from a source. If the track from the source is already used an playing, the player carries on. /// </summary> /// <param name="streamSource">The object the stream is created from.</param> /// <param name="streamBuilder">The function that creates the stream if needed.</param> /// <param name="reset">Whether the track should be reset to initial position or not.</param> public void Play(object streamSource, Func <WaveStream> streamBuilder, bool reset = false) { Select(streamSource, streamBuilder); if (reset) { CurrentStream.Position = 0; } CurrentOut.Play(); }
/// <summary> /// Stops the track and resets the stream position. /// </summary> public void Stop() { if (CurrentOut == null) { return; } CurrentOut.Stop(); CurrentStream.Position = 0; }
/// <summary> /// Selects a track without playing it. If the stream is already selected, the player carries on. /// </summary> /// <param name="stream">The track to select.</param> public void Select(WaveStream stream) { if (CurrentStream != stream) { CurrentOut?.Dispose(); CurrentStream?.Dispose(); CurrentOut = new WaveOut(WaveCallbackInfo.FunctionCallback()); // using the function callback makes playback independent of GUI thread, apparently CurrentOut.PlaybackStopped += PlaybackStopped; CurrentOut.Volume = _Volume; CurrentStream = stream; CurrentOut.Init(stream); StreamSource = null; } }
/// <summary> /// Resumes the audio after pausing. /// </summary> public void Resume() => CurrentOut.Resume();
/// <summary> /// Pauses the audio. /// </summary> public void Pause() => CurrentOut.Pause();