示例#1
0
 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 { }
         }
     }
 }
示例#2
0
 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();
 }
示例#3
0
 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 ();
 }