public MusicPanel(string path) { PanelInisialize(); this.MusicPath = path; MusicTitle.Text = TagFile.GetTitle(path); MusicCover.Image = TagFile.GetCover(path).GetThumbnailImage(40, 40, null, IntPtr.Zero); }
private void EditFormInitialise(int Index) { TextBoxGenre.AutoCompleteCustomSource.AddRange(TagLib.Genres.Audio); string TrackPath = MainForm.Music[Index]; TextBoxTitle.Text = TagFile.GetTitle(TrackPath); TextBoxArtists.Text = TagFile.GetArtists(TrackPath); TextBoxAlbum.Text = TagFile.GetAlbum(TrackPath); TextBoxTrack.Text = TagFile.GetTrack(TrackPath); TextBoxTrackCount.Text = TagFile.GetTrackCount(TrackPath); TextBoxGenre.Text = TagFile.GetGenre(TrackPath); RichTextBoxLyrics.Text = TagFile.GetLyrics(TrackPath); PictureBoxCover.Image = TagFile.GetCover(TrackPath); TextBoxYear.Text = TagFile.GetYear(TrackPath); this.Text = TextBoxTitle.Text; }
private void MusicInitialize(string path) { if (WaveOutEvent != null) { WaveOutEvent.Dispose(); } if (AudioFileReader != null) { AudioFileReader.Dispose(); } try { AudioFileReader = new AudioFileReader(path); WaveOutEvent = new WaveOutEvent(); WaveOutEvent.Init(AudioFileReader); WaveOutEvent.Play(); if (!AppTimer.Enabled) { AppTimer.Start(); } MusicState = MusicState.Play; ButtonPlayPause.BackgroundImage = Properties.Resources.Pause; PlayAndPauseToolStripMenuItem.Text = "Pause"; PlaybackBarControl.Max = Convert.ToInt32(ConvertFrom.TimeToSeconds(AudioFileReader.TotalTime)); AudioFileReader.Volume = TrackBarVolumeState.Value / 10f; // This condition is related to the (Exception) Code Part // The Path Variable will be changed to the CurrentPlayingMusic, for get the original audio meatdata if (IsFileGenerateException) { path = Music[CurrentPlayingMusicIndex]; } // Change the Label Text to the Music Total Time // Change the PictureBox BackgroundImage to the Music Cover LabelMusicEndTime.Text = AudioFileReader.TotalTime.ToString(@"mm\:ss"); PictureBoxMusicCover.BackgroundImage = TagFile.GetCover(path); // Change the Form Title to the Music Title + Artist this.Text = TagFile.GetArtists(path) + " - " + TagFile.GetTitle(path); // Change the Current MusicPanel BackgroundColor, and reset the others foreach (MusicPanel musicPanel in FlowLayoutPanelMusic.Controls) { if (musicPanel.MusicPath == path) { musicPanel.BackColor = Color.FromArgb(28, 28, 28); } else { musicPanel.BackColor = Color.Transparent; } } // Reset the "IsFileGenerateException" value to false IsFileGenerateException = false; } catch { try { // If Audio File GenerateException, Convert it to 'wav' and save it // on a Temp File, so we can play it later AudioFileReader = null; using (var reader = new MediaFoundationReader(Music[CurrentPlayingMusicIndex])) { if (!Directory.Exists("TempFiles/")) { Directory.CreateDirectory("TempFiles/"); } // Save the 'wav' audio on the Temp File WaveFileWriter.CreateWaveFile("TempFiles/temp.wav", reader); } // Change the "IsFileGenerateException" value to true, because the File is Generate Exception IsFileGenerateException = true; // Try to play the Temp File, if isn't played alert a message to the user MusicInitialize("TempFiles/temp.wav"); } catch (Exception Ex) { MessageBox.Show("This song is hard for us to play it for you, Please play another one." + Environment.NewLine + "(" + Ex.Message + ")", "We are sorry!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }