Esempio n. 1
0
 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;
 }
Esempio n. 2
0
        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));
            }
        }
Esempio n. 3
0
        /// <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));
            }
        }