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的效果也挺好的 就用这个代替了! } }
/// <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); }