Exemple #1
0
        public void PlaySound(CachedSound sound)
        {
            switch (sound.Type)
            {
            case TYPE_SOURCE.FILE_LOCAL:
                AddMixerInput(new CachedSoundSampleProvider(sound));
                break;

            case TYPE_SOURCE.FILE_MP3_ONLINE:
                using (MemoryStream mp3file = new MemoryStream(sound.AudioData_FILE_MP3_ONLINE))
                {
                    using (WaveStream blockAlignedStream = new BlockAlignReductionStream(WaveFormatConversionStream.CreatePcmStream(
                                                                                             new Mp3FileReader(mp3file))))
                    {
                        using (WaveOut waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
                        {
                            waveOut.Init(blockAlignedStream);
                            waveOut.Play();
                            while (waveOut.PlaybackState == PlaybackState.Playing)
                            {
                                System.Threading.Thread.Sleep(100);
                            }
                        }
                    }
                }
                break;
            }
        }
Exemple #2
0
 public CachedSoundSampleProvider(CachedSound cachedSound)
 {
     this.cachedSound = cachedSound;
 }