示例#1
0
 /// <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();
 }
示例#2
0
 /// <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();
 }
示例#3
0
 /// <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();
 }
示例#4
0
        /// <summary>
        /// Stops the track and resets the stream position.
        /// </summary>
        public void Stop()
        {
            if (CurrentOut == null)
            {
                return;
            }

            CurrentOut.Stop();
            CurrentStream.Position = 0;
        }
示例#5
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;
            }
        }
示例#6
0
 /// <summary>
 /// Resumes the audio after pausing.
 /// </summary>
 public void Resume()
 => CurrentOut.Resume();
示例#7
0
 /// <summary>
 /// Pauses the audio.
 /// </summary>
 public void Pause()
 => CurrentOut.Pause();