public SoundTimeSource(string fileName) { waveOutDevice = new WaveOut(); audioFileReader = new AudioFileReader(fileName); loopingWaveStream = new SoundLoopStream(audioFileReader); loopingWaveStream.EnableLooping = false; waveOutDevice.Init(loopingWaveStream); waveOutDevice.PlaybackStopped += (s, a) => playing = false; length = (float)audioFileReader.TotalTime.TotalSeconds; }
public void PlaySound(string fileName, bool looped = false) { var input = new AudioFileReader(fileName); if (looped) { var reader = new SoundLoopStream(input); var sampleChannel = new SampleChannel(reader, false); AddMixerInput(sampleChannel); } else { AddMixerInput(new AutoDisposeSampleProvider(input, input)); } }
/// <summary> /// Plays sound from a stream; you get unbuffered access if you usse a file stream /// and buffered access if you use a memory stream /// </summary> /// <param name="stream"></param> public void PlaySound(Stream stream, bool looped = false) { WaveStream reader = FindCorrectWaveStream(stream); if (looped) { reader = new SoundLoopStream(reader); var sampleChannel = new SampleChannel(reader, false); AddMixerInput(sampleChannel); } else { var sampleChannel = new SampleChannel(reader, false); AddMixerInput(new AutoDisposeSampleProvider(sampleChannel, reader)); } }