/// <summary> /// Load spefic frame information /// </summary> /// <param name="FrameID">FrameID to load</param> /// <param name="FileAddress">FileAddress to read tag from</param> private void LoadFrameFromFile(string FrameID, string FileAddress) { ID3v2 LinkedInfo = new ID3v2(FileAddress, false); LinkedInfo.Filter.Add(FrameID); LinkedInfo.FilterType = FilterTypes.LoadFiltersOnly; LinkedInfo.Load(); if (LinkedInfo.HadError) foreach (ID3Error IE in LinkedInfo.Errors) _Errors.Add(new ID3Error("In Linked Info(" + FileAddress + "): " + IE.Message, IE.FrameID)); foreach (TextFrame TF in LinkedInfo._TextFrames) _TextFrames.Add(TF); foreach (UserTextFrame UT in LinkedInfo._UserTextFrames) _UserTextFrames.Add(UT); foreach (PrivateFrame PF in LinkedInfo._PrivateFrames) _PrivateFrames.Add(PF); foreach (TextWithLanguageFrame TWLF in LinkedInfo._TextWithLangFrames) _TextWithLangFrames.Add(TWLF); foreach (SynchronisedText ST in LinkedInfo._SynchronisedTextFrames) _SynchronisedTextFrames.Add(ST); foreach (AttachedPictureFrame AP in LinkedInfo._AttachedPictureFrames) _AttachedPictureFrames.Add(AP); foreach (GeneralFileFrame GF in LinkedInfo._EncapsulatedObjectFrames) _EncapsulatedObjectFrames.Add(GF); foreach (PopularimeterFrame PF in LinkedInfo._PopularimeterFrames) _PopularimeterFrames.Add(PF); foreach (AudioEncryptionFrame AE in LinkedInfo._AudioEncryptionFrames) _AudioEncryptionFrames.Add(AE); // Link to LinkFrame is not available foreach (TermOfUseFrame TU in LinkedInfo._TermOfUseFrames) _TermOfUseFrames.Add(TU); foreach (DataWithSymbolFrame DWS in LinkedInfo._DataWithSymbolFrames) _DataWithSymbolFrames.Add(DWS); foreach (BinaryFrame BF in LinkedInfo._UnknownFrames) _UnknownFrames.Add(BF); if (LinkedInfo._MCDIFrame != null) _MCDIFrame = LinkedInfo._MCDIFrame; if (LinkedInfo._SYTCFrame != null) _SYTCFrame = LinkedInfo._SYTCFrame; if (LinkedInfo._PCNTFrame != null) _PCNTFrame = LinkedInfo._PCNTFrame; if (LinkedInfo._RBUFFrame != null) _RBUFFrame = LinkedInfo._RBUFFrame; if (LinkedInfo._OWNEFrame != null) _OWNEFrame = LinkedInfo._OWNEFrame; if (LinkedInfo._COMRFrame != null) _COMRFrame = LinkedInfo._COMRFrame; if (LinkedInfo._RVRBFrame != null) _RVRBFrame = LinkedInfo._RVRBFrame; if (LinkedInfo._EQUAFrame != null) _EQUAFrame = LinkedInfo._EQUAFrame; if (LinkedInfo._RVADFrame != null) _RVADFrame = LinkedInfo._RVADFrame; if (LinkedInfo._ETCOFrame != null) _ETCOFrame = LinkedInfo._ETCOFrame; }
private void Menu_DeleteLyrics_Click(object sender, RoutedEventArgs e) { int SelectedIndex = DataListBox.SelectedIndex; if (SelectedIndex < 0 || SelectedIndex > SongList.Count - 1) return; if (ShowMessageBoxOkCancel("\n确定要删除当前歌曲歌词吗?") == 1) { ID3v2 id3v2 = new ID3v2(SongList[SelectedIndex].SongPath, true); if (id3v2.TextWithLanguageFrames.Count > 0) { id3v2.TextWithLanguageFrames.Clear(); } id3v2.Save(); SongList[SelectedIndex].SongLyrics = null; SongList[SelectedIndex].SongLyricsUnsaved = null; DataListBox.SelectedIndex = -1; DataListBox.SelectedIndex = SelectedIndex; } }
private void AddSongs(string[] FileNames) { if (FileNames == null) return; if (FileNames.Length >= 100) { if (ShowMessageBoxOkCancel("您选择的歌曲数量超过100,这样可能会导致软件占用较多内存,确定要继续吗?\n(推荐您分次处理,每次处理的歌曲控制在100以内)") == 0) { return; } } char[] CharToDelete = { '\0', ' ' }; Image_Helper.Visibility = Visibility.Hidden; Label_URL.Visibility = Visibility.Hidden; foreach (string FileName in FileNames) { if (System.IO.Path.GetExtension(FileName).ToUpper() != ".MP3") continue; BitmapImage HasAlbum = null; string HasLyrics = null; string Title = "", Artist = "", Album = ""; ID3v2 id3v2 = new ID3v2(FileName, true); if (id3v2.TextWithLanguageFrames.Count > 0) { for (int i = 0; i < id3v2.TextWithLanguageFrames.Count; i++) { if (id3v2.TextWithLanguageFrames.Items[i].FrameID == "USLT") { HasLyrics = id3v2.TextWithLanguageFrames.Items[i].Text.Trim(); break; } } } if (id3v2.AttachedPictureFrames.Count > 0) { for (int i = 0; i < id3v2.AttachedPictureFrames.Count; i++) { if (id3v2.AttachedPictureFrames.Items[i].FrameID == "APIC") { HasAlbum = new BitmapImage(); HasAlbum.BeginInit(); HasAlbum.StreamSource = id3v2.AttachedPictureFrames.Items[0].Data; try { HasAlbum.EndInit(); } catch { HasAlbum = null; } break; } } } if (id3v2.TextFrames.Count > 0) { for (int i = 0; i < id3v2.TextFrames.Count; i++) { if (id3v2.TextFrames.Items[i].FrameID == "TIT2") Title = id3v2.TextFrames.Items[i].Text; if (id3v2.TextFrames.Items[i].FrameID == "TPE1") Artist = id3v2.TextFrames.Items[i].Text; if (id3v2.TextFrames.Items[i].FrameID == "TALB") Album = id3v2.TextFrames.Items[i].Text; } } ID3v1 id3v1 = new ID3v1(FileName, true); Title = IsStringNullOrEmpry(Title) ? id3v1.Title : Title; Artist = IsStringNullOrEmpry(Artist) ? id3v1.Artist : Artist; Album = IsStringNullOrEmpry(Album) ? id3v1.Album : Album; if (IsStringNullOrEmpry(Title)) Title = ""; if (IsStringNullOrEmpry(Artist)) Artist = ""; if (IsStringNullOrEmpry(Album)) Album = ""; SongList.Add(new Song(FileName, Title.TrimEnd(CharToDelete), Artist.TrimEnd(CharToDelete), Album.TrimEnd(CharToDelete), HasAlbum, HasLyrics)); System.Windows.Forms.Application.DoEvents(); //这个地方加多线程实在是不好加 因为有一个OpenFileDialog 而且结果是一个string[] 直接用object传到多线程里面会出问题 //其实DoEvents的效果也挺好的 就用这个代替了! } }
private void Menu_DeleteAlbum_Click(object sender, RoutedEventArgs e) { int SelectedIndex = DataListBox.SelectedIndex; if (SelectedIndex < 0 || SelectedIndex > SongList.Count - 1) return; if (ShowMessageBoxOkCancel("\n确定要删除当前歌曲封面吗?") == 1) { ID3v2 id3v2 = new ID3v2(SongList[SelectedIndex].SongPath, true); if (id3v2.AttachedPictureFrames.Count > 0) { id3v2.AttachedPictureFrames.Clear(); } id3v2.Save(); SongList[SelectedIndex].SongAlbum = null; DataListBox.SelectedIndex = -1; DataListBox.SelectedIndex = SelectedIndex; } }
private void Button_SaveSong_Click(object sender, RoutedEventArgs e) { //保存信息 //悲催的代码让我的歌曲化为灰烬…… try { int NowSelect = DataListBox.SelectedIndex; if (NowSelect < 0) return; string FileName = SongList[NowSelect].SongPath; bool NeedToSave = false; ID3v2 id3v2 = new ID3v2(FileName, true); id3v2.TextFrames.Add(new ID3.ID3v2Frames.TextFrames.TextFrame("TIT2", 0, TextBox_Title.Text, TextEncodings.UTF_16, 3)); id3v2.TextFrames.Add(new ID3.ID3v2Frames.TextFrames.TextFrame("TPE1", 0, TextBox_Artist.Text, TextEncodings.UTF_16, 3)); id3v2.TextFrames.Add(new ID3.ID3v2Frames.TextFrames.TextFrame("TALB", 0, TextBox_Album.Text, TextEncodings.UTF_16, 3)); if (Checkbox_lyrics.IsChecked == true && (string)Checkbox_lyrics.Content == "保存歌曲歌词" && !string.IsNullOrEmpty(SongList[NowSelect].SongLyricsUnsaved)) { NeedToSave = true; SongList[NowSelect].SongLyrics = SongList[NowSelect].SongLyricsUnsaved; id3v2.TextWithLanguageFrames.Add(new ID3.ID3v2Frames.TextFrames.TextWithLanguageFrame("USLT", 0, SongList[NowSelect].SongLyrics, "", TextEncodings.UTF_16, "eng")); } if (Checkbox_albumpicture.IsChecked == true && (string)Checkbox_albumpicture.Content == "保存专辑封面") { NeedToSave = true; BitmapImage Bitmap = (BitmapImage)Image_album.Source; while (Bitmap.IsDownloading) { Thread.Sleep(50); System.Windows.Forms.Application.DoEvents(); } SongList[NowSelect].SongAlbum = Bitmap; JpegBitmapEncoder encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(Bitmap)); MemoryStream stream = new MemoryStream(); encoder.Save(stream); id3v2.AttachedPictureFrames.Add(new ID3.ID3v2Frames.BinaryFrames.AttachedPictureFrame(0, "", TextEncodings.UTF_16, "image/jpeg", ID3.ID3v2Frames.BinaryFrames.AttachedPictureFrame.PictureTypes.Cover_Front, stream)); } if (NeedToSave) { id3v2.Save(); } } catch (Exception ex) { MessageBox.Show("保存出错,请将下列信息反馈到官方博客,以帮助我们改进软件。谢谢!\n(官方博客:http://www.4321.la,下列信息Ctrl+C可复制)" + ex.Message); } }
private void Button_Lyrics_OK_Click(object sender, RoutedEventArgs e) { int SelectedIndex = DataListBox.SelectedIndex; if (SelectedIndex < 0 || SelectedIndex > SongList.Count - 1) return; ID3v2 id3v2 = new ID3v2(SongList[SelectedIndex].SongPath, true); if (id3v2.TextWithLanguageFrames.Count > 0) { id3v2.TextWithLanguageFrames.Clear(); } id3v2.TextWithLanguageFrames.Add(new ID3.ID3v2Frames.TextFrames.TextWithLanguageFrame("USLT", 0, Textbox_EditLyrics.Text, "", TextEncodings.UTF_16, "eng")); SongList[SelectedIndex].SongLyrics = Textbox_EditLyrics.Text; id3v2.Save(); DataListBox.SelectedIndex = -1; DataListBox.SelectedIndex = SelectedIndex; Sb5.Begin(); DataListBox.IsEnabled = true; }
/// <summary> /// Create new ID3 Info class /// </summary> /// <param name="FileAddress">FileAddress for read ID3 info</param> /// <param name="LoadData">Indicate load data in constructor or not</param> public ID3Info(string FilePath, bool LoadData) { _ID3v1 = new ID3v1(FilePath, LoadData); _ID3v2 = new ID3v2(FilePath, LoadData); }
//جلب ملف الوسائط private void LoadFile(string path) { if (ap.IsOpened) ap.Close(); string FileName; FileName = System.IO.Path.GetFileName(path); sk.FileName = FileName; this.Invalidate(); Mp3Info = null; if (videozoom.Value > 0) videozoom.Value = 0; trackBar2.Value = 0; try { Mp3Info = new ID3v2(path, true); ap.Open(path); ap.Owner = p1; ap.Volume = (int)tv.Value; ap.Rate = (int)track_Speed.Value; ap.Balance = (int)track_Balance.Value; trackBar2.Maximum = (int)ap.Duration; if (ap.HasVideo) { //effectVideo(); button10.Enabled = true; button3.Enabled = true; videozoom.Enabled = true; timer2.Enabled = false; this.Invalidate(); } else { button10.Enabled = false; button3.Enabled = false; videozoom.Enabled = false; /*switch (Visual) { case "wave": timer2.Enabled = true; break; case "AlbumPicture": //GetMp3Info(path); break; case "none": p1.BackgroundImageLayout = ImageLayout.Center; p1.BackgroundImage = Reso.login; break; }*/ this.Invalidate(); } } catch { MessageBox.Show("قد يكون الملف غير صالح أو تأكد من مسار الملف أو أن الكودك غير موجود على الكمبيوتر"); } //catch (Exception m) { MessageBox.Show(m.ToString()); } if (this.WindowState ==FormWindowState.Normal) { if (list_show == false) { p1.Width = this.ClientRectangle.Width -sk.Border_Size2*2; p1.Left = this.ClientRectangle.Left+3; this.Left = this.Left -6; panel_Control.Width = ClientRectangle.Width-sk.Border_Size2*2 ; panel_Control.Left = this.ClientRectangle.Left + 3; p1.Height = this.ClientRectangle.Height -5- panel_Control.Height-sk.Panel_Move_Size2-(sk.Border_Size2*2); } else { p1.Width = this.ClientRectangle.Width - panel_list.Width-(sk.Border_Size2*2); panel_Control.Width = this.ClientRectangle.Width - panel_list.Width-11; p1.Height = this.ClientRectangle.Height -5- panel_Control.Height-(sk.Border_Size2*2)-sk.Panel_Move_Size2; } } else if (this.WindowState == FormWindowState.Maximized) { if (list_show == false) { p1.Width = this.ClientRectangle.Width-(sk.Border_Size2 * 2); panel_Control.Width = this.ClientRectangle.Width-6-5; p1.Height = this.ClientRectangle.Height - panel_Control.Height - (sk.Border_Size2 * 2) - sk.Panel_Move_Size2; } else { p1.Width = this.ClientRectangle.Width - panel_list.Width-(sk.Border_Size2 * 2); panel_Control.Width = this.ClientRectangle.Width - panel_list.Width-11; p1.Height = this.ClientRectangle.Height - panel_Control.Height - (sk.Border_Size2 * 2) - sk.Panel_Move_Size2; } //p1.Width = this.ClientRectangle.Width; //p1.Height = this.Height - panel_Control.Height; } SetLength(); }