public void StopAudio() { TargetAudioFile = ""; if (waveOutDevice != null) { waveOutDevice.Stop(); } if (audioFileReader != null) { audioFileReader.Dispose(); audioFileReader = null; } if (vorbisFileReader != null) { vorbisFileReader.Dispose(); vorbisFileReader = null; } if (waveOutDevice != null) { waveOutDevice.Dispose(); waveOutDevice = null; } this.targetState = TargetState.NOTHING; }
public void PlayRandomTrack() { Random random = new Random(); this.TargetAudioFile = this.Playlist[random.Next(this.Playlist.Count)]; this.waveOutDevice = new WaveOut(); if (this.TargetAudioFile.EndsWith(".mp3") || this.TargetAudioFile.EndsWith(".wav")) { this.audioFileReader = new AudioFileReader(this.TargetAudioFile); this.waveOutDevice.Init(audioFileReader); } else if (this.TargetAudioFile.EndsWith(".ogg")) { this.vorbisFileReader = new VorbisFileReader(this.TargetAudioFile); this.waveOutDevice.Init(vorbisFileReader); } this.waveOutDevice.Volume = 1.0f; // Unfortunately, VorbisFileReader does not have volume control this.waveOutDevice.Play(); this.targetState = TargetState.NOTHING; }