private void PlaySound(SaveFile.Sound Item) { foreach (System.Windows.Forms.TreeNode DeviceNode in this.treeView1.Nodes) { if (DeviceNode.Checked && DeviceNode.Tag != null && ((SaveFile.Device)DeviceNode.Tag).CurrentDevice != null) { try { NAudio.Wave.WaveStream Stream; if (Item.SndFormat == SoundFormat.OGG) { Stream = new NAudio.Vorbis.VorbisWaveReader(Item.FilePath); } else if (Item.SndFormat == SoundFormat.WAV) { Stream = new NAudio.Wave.WaveFileReader(Item.FilePath); } else if (Item.SndFormat == SoundFormat.MP3) { Stream = new NAudio.Wave.Mp3FileReader(Item.FilePath); } else if (Item.SndFormat == SoundFormat.AIFF) { Stream = new NAudio.Wave.AiffFileReader(Item.FilePath); } else { throw new System.NotSupportedException(); } if (this.UserData.LoopEnabled) { Stream = new LoopStream(Stream); } NAudio.Wave.WasapiOut PlayAudio = new NAudio.Wave.WasapiOut((NAudio.CoreAudioApi.MMDevice)((SaveFile.Device)DeviceNode.Tag).CurrentDevice, NAudio.CoreAudioApi.AudioClientShareMode.Shared, true, 100); this.CurrentlyPlaying.Add(PlayAudio); { PlayAudio.Init(Stream); PlayAudio.Play(); } PlayAudio.PlaybackStopped += this.WaveOut_PlaybackStopped; } catch (System.FormatException Ex) { LucasStuff.Message.Show(Ex.Message, "An error occured while playing", LucasStuff.Message.Buttons.OK, LucasStuff.Message.Icon.Error); return; } catch (System.IO.InvalidDataException Ex) { LucasStuff.Message.Show(Ex.Message, "An error occured while playing", LucasStuff.Message.Buttons.OK, LucasStuff.Message.Icon.Error); return; } catch (System.IO.FileNotFoundException Ex) { System.Windows.Forms.DialogResult Result = LucasStuff.Message.Show(Ex.Message + "\n\nShould this file be removed from your audio listing?", "An error occured while playing", LucasStuff.Message.Buttons.YesNo, LucasStuff.Message.Icon.Error); if (Result == System.Windows.Forms.DialogResult.Yes) { //this.DeleteSounds(); // HACK: fix this before PC 1.0 Update #1 } return; } } } }
public SFXNode(string title) { done = false; fx_in = null; fx_out = null; this.title = title; string path = Program.tools + "sfx\\" + title; if (File.Exists(path + ".mp3")) { fx_in = new NAudio.Wave.Mp3FileReader(path + ".mp3"); } else { fx_in = new NVorbis.NAudioSupport.VorbisWaveReader(path + ".ogg"); } fx_out = new NAudio.Wave.WasapiOut(LSSettings.singleton.devRec.mm, NAudio.CoreAudioApi.AudioClientShareMode.Shared, false, 100); fx_out.PlaybackStopped += new EventHandler<NAudio.Wave.StoppedEventArgs>(fx_out_PlaybackStopped); fx_out.Init(fx_in); fx_out.Play(); }
public Mixer() { output = new NAudio.Wave.WasapiOut(NAudio.CoreAudioApi.AudioClientShareMode.Shared, true, 300); output.Init(this); output.Play(); }
void playFX(LSDevice dev) { if (unFxTimer == null) { unFxTimer = new Timer(); unFxTimer.Interval = 3000; unFxTimer.Tick += delegate(object oa, EventArgs ob) { unFX(); }; } try { if (disregardEvents) return; unFX(); fx_stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Loopstream.res.sc.wav"); //fx_mp3 = new NAudio.Wave.Mp3FileReader(fx_stream); fx_wav = new NAudio.Wave.WaveFileReader(fx_stream); fx_out = new NAudio.Wave.WasapiOut(dev.mm, NAudio.CoreAudioApi.AudioClientShareMode.Shared, false, 100); fx_out.Init(fx_wav); fx_out.Play(); unFxTimer.Start(); } catch { } }