private void ChangeVolume(object sender, EventArgs e) { if (this.listViewSongs.SelectedItems.Count > 0) { if (this.listViewSongs.SelectedItems[0].Group != this.listViewSongs.Groups["customMusic"]) { using (VolumeMessageBox messageBox = new VolumeMessageBox(this.lastVolume)) { if (messageBox.ShowDialog(this) == DialogResult.OK) { this.lastVolume = messageBox.NewVolume; SaveSettings(null, null); if (this.listViewSongs.SelectedItems[0].ImageIndex == 1) { this.listViewSongs.SelectedItems[0].ImageIndex = 0; this.currentSong.Stop(); this.playing = false; this.playingCustom = false; this.buttonPlay.Text = "Play"; } if (this.lastVolume == 100) { if (File.Exists(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", this.listViewSongs.SelectedItems[0].SubItems[1].Text))) { File.Delete(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", this.listViewSongs.SelectedItems[0].SubItems[1].Text)); } this.listViewSongs.SelectedItems[0].SubItems[3].Text = ""; } else { using (WaveFileReader reader = new WaveFileReader(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", this.listViewSongs.SelectedItems[0].SubItems[1].Text))) { using (WaveFileWriter writer = new WaveFileWriter(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Custom Music", "Modified", this.listViewSongs.SelectedItems[0].SubItems[1].Text), reader.WaveFormat)) { float[] samples = reader.ReadNextSampleFrame(); while (samples != null) { for (int i = 0; i < samples.Length; i++) { writer.WriteSample(samples[i] * ((float)this.lastVolume / 100.0f)); } samples = reader.ReadNextSampleFrame(); } } } this.listViewSongs.SelectedItems[0].SubItems[3].Text = "*"; } } } } } }
public static DialogResult Show(Form parent, int currentVolume) { using (var form = new VolumeMessageBox(currentVolume)) { return(form.ShowDialog(parent)); } }