private void SoundViewDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e) { System.Windows.Forms.ListViewHitTestInfo hit = this.listView1.HitTest(e.Location); if (hit.Item != null) { SaveFile.Sound Item = ((SaveFile.Sound)hit.Item.Tag); this.PlaySound(Item); } }
private void AddSoundToList(SaveFile.Sound Snd) { System.Windows.Forms.ListViewItem Item = new System.Windows.Forms.ListViewItem { Text = GetSoundListText(Snd.FilePath) }; string HotKeyPreview = ""; if (Snd.HasHotKey) { System.Windows.Forms.KeysConverter KeyConverter = new System.Windows.Forms.KeysConverter(); if (Snd.HotKeyControl) { HotKeyPreview += KeyConverter.ConvertToString(System.Windows.Forms.Keys.Control); } if (Snd.HotKeyAlt) { HotKeyPreview += (HotKeyPreview.Length != 0 ? "+" : "") + KeyConverter.ConvertToString(System.Windows.Forms.Keys.Alt); } if (Snd.HotKeyShift) { HotKeyPreview += (HotKeyPreview.Length != 0 ? "+" : "") + KeyConverter.ConvertToString(System.Windows.Forms.Keys.Shift); } if (Snd.Key != System.Windows.Forms.Keys.None) { HotKeyPreview += (HotKeyPreview.Length != 0 ? "+" : "") + KeyConverter.ConvertToString(Snd.Key); } } Item.SubItems.Add(HotKeyPreview.Length != 0 ? HotKeyPreview : "(none)"); Item.Tag = Snd; Snd.Item = Item; this.listView1.Items.Add(Item); }
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; } } } }