Dispose() 공개 메소드

Closes this WaveOut device
public Dispose ( ) : void
리턴 void
예제 #1
0
 /// <summary>
 /// Releases unmanaged and - optionally - managed resources.
 /// </summary>
 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
             if (output != null)
             {
                 output.Stop();
                 output.Dispose();
                 output = null;
             }
             if (reduce != null)
             {
                 reduce.Dispose();
                 reduce = null;
             }
         }
         _disposed = true;
     }
 }
예제 #2
0
 void playSound(String fileName)
 {
     var output = new WaveOutEvent();
     try
     {
         var player = new WaveFileReader(fileName);
         output.Init(player);
         output.Play();
         while (output.PlaybackState == PlaybackState.Playing && sounds.Count == 0)
         {
             Thread.Sleep(100);
         }
         output.Dispose();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
     }
 }
예제 #3
0
파일: Sounds.cs 프로젝트: rexperalta/OCTGN
 public static void PlayGameSound(GameSound sound)
 {
     //var isSubscribed = SubscriptionModule.Get().IsSubscribed ?? false;
     //if (isSubscribed == false)return;
     if (Prefs.EnableGameSound == false) return;
     Log.InfoFormat("Playing game sound {0}", sound.Name);
     if (!sound.Src.ToLowerInvariant().EndsWith(".mp3"))
     {
         Log.InfoFormat("Playing game sound {0} as wav", sound.Name);
         PlaySound(sound.Src);
         return;
     }
     Task.Factory.StartNew(() =>
         {
             try
             {
                 Log.InfoFormat("Playing game sound {0} as mp3", sound.Name);
                 var mp3Reader = new Mp3FileReader(sound.Src);
                 var stream = new WaveChannel32(mp3Reader) { PadWithZeroes = false };
                 DisposeObjects.Add(mp3Reader);
                 DisposeObjects.Add(stream);
                 {
                     stream.Position = 0;
                     Mixer.AddMixerInput(stream);
                     lock (Mixer)
                     {
                         if (WaveOut == null)
                         {
                             Log.Info("Starting up wave out");
                             WaveOut = new WaveOutEvent();
                             WaveOut.Init(new SampleToWaveProvider(Mixer));
                             WaveOut.PlaybackStopped += (sender, args) =>
                             {
                                 WaveOut.Dispose();
                                 WaveOut = null;
                             };
                             WaveOut.Play();
                         }
                     }
                     Log.InfoFormat("Initializing game sound {0} as mp3", sound.Name);
                 }
             }
             catch (Exception e)
             {
                 Log.Warn("PlayGameSound Error", e);
                 Program.GameMess.Warning("Cannot play sound {0}, it must be in the format 44100:2", sound.Name);
             }
         });
 }
예제 #4
0
파일: Form1.cs 프로젝트: KR0SIV/EAS-Encoder
        private void button1_Click(object sender, EventArgs e)
        {
            if (player != null)
            {
                player.Stop();
                return;
            }

            if (!ValidateInput())
            {
                return;
            }

            _start = dateStart.Value.ToUniversalTime();
            _senderId = txtSender.Text;
            _length = ZeroPad(comboLengthHour.Text, 2) + ZeroPad(comboLengthMinutes.Text, 2);

            var newMessage = new EASMessage(_selectedOriginator.Id, _selectedAlertCode.Id,
                Regions, _length, _start, _senderId);


            var messageStream = EASEncoder.EASEncoder.GetMemoryStreamFromNewMessage(newMessage, chkEbsTones.Checked,
                chkNwsTone.Checked, formatAnnouncement(txtAnnouncement.Text));
            btnGeneratePlay.Text = "Stop Playing";
            WaveStream mainOutputStream = new RawSourceWaveStream(messageStream, new WaveFormat());
            var volumeStream = new WaveChannel32(mainOutputStream);
            volumeStream.PadWithZeroes = false;

            player = new WaveOutEvent();
            player.PlaybackStopped += (o, args) =>
            {
                player.Dispose();
                player = null;
                btnGeneratePlay.Text = "Generate && Play";
            };

            player.Init(volumeStream);

            player.Play();
        }