public void StopMusic() { if (MusicState == AudioPlayState.Playing) { MusicStreamer.Stop(); MusicStreamer.Dispose(); MusicDecoder.Dispose(); MusicStreamer = null; if (Stream != null) { try { Stream.Dispose(); // Analysis disable once EmptyGeneralCatchClause } catch { } } } }
public void PlayMusic(string filename) { StopMusic(); Stream = File.OpenRead(filename); MusicDecoder = DecoderFactory.GetDecoderFromStream(Stream); MusicStreamer = new StreamingAudio(Device, MusicDecoder.Format, MusicDecoder.SampleRate); MusicStreamer.BufferNeeded += (instance, buffer) => MusicDecoder.Read(buffer.Length, buffer); MusicStreamer.PlaybackFinished += (sender, e) => { if (loopMusic) { PlayMusic(filename); } else { MusicStreamer.Dispose(); MusicDecoder.Dispose(); MusicStreamer = null; } }; MusicStreamer.Play(); }
public void PlayMusic(string filename) { StopMusic (); Stream = File.OpenRead (filename); MusicDecoder = DecoderFactory.GetDecoderFromStream (Stream); MusicStreamer = new StreamingAudio (Device, MusicDecoder.Format, MusicDecoder.SampleRate); MusicStreamer.BufferNeeded += (instance, buffer) => MusicDecoder.Read (buffer.Length, buffer); MusicStreamer.PlaybackFinished += (sender, e) => { if (loopMusic) PlayMusic (filename); else { MusicStreamer.Dispose (); MusicDecoder.Dispose (); MusicStreamer = null; } }; MusicStreamer.Play (); }