/// <summary> /// Attaches the cover file to the mp3's picture frames. /// </summary> private static void AttachCover(string p_musicPath, string p_coverPath) { UltraID3 myMp3 = new UltraID3(); myMp3.Read(p_musicPath); System.Drawing.Bitmap cover = new System.Drawing.Bitmap(p_coverPath); // cover = new System.Drawing.Bitmap(cover.GetThumbnailImage(100, 100, null, IntPtr.Zero)); ID3PictureFrame AlbumArt = new ID3PictureFrame( cover, PictureTypes.CoverFront, "Attached picture", TextEncodingTypes.ISO88591); myMp3.ID3v23Tag.Frames.Add(AlbumArt); myMp3.ID3v23Tag.WriteFlag = true; myMp3.Write(); myMp3 = null; }
public static void UpdateId3(Music objEntity) { string path = string.Empty; if (string.IsNullOrWhiteSpace(objEntity.FilePath) == false && string.IsNullOrWhiteSpace(objEntity.FileName) == false) { path = Path.Combine(objEntity.FilePath, objEntity.FileName); } else if (string.IsNullOrWhiteSpace(objEntity.FilePath) == true && string.IsNullOrWhiteSpace(objEntity.FileName) == false) { path = objEntity.FileName; } else if (string.IsNullOrWhiteSpace(objEntity.FilePath) == false && string.IsNullOrWhiteSpace(objEntity.FileName) == true) { path = objEntity.FilePath; } if (string.IsNullOrWhiteSpace(path) == false) { if (Directory.Exists(path)) { int index; byte[] cover = RessourcesServices.GetDefaultCover(objEntity, out index); DirectoryInfo folder = new DirectoryInfo(path); FileInfo[] files = folder.GetFiles("*.mp3", SearchOption.TopDirectoryOnly); files = files.Concat(folder.GetFiles("*.flc", SearchOption.TopDirectoryOnly)).ToArray(); files = files.Concat(folder.GetFiles("*.flac", SearchOption.TopDirectoryOnly)).ToArray(); if (files.Any()) { foreach (FileInfo file in files) { switch (file.Extension) { case ".mp3": IID3v2 objMp3Tag = ID3v2Helper.CreateID3v2(file.FullName); if (objMp3Tag != null) { objMp3Tag.Album = objEntity.Album; objMp3Tag.Artist = objEntity.Artists.First().FulleName; objMp3Tag.Accompaniment = objEntity.Artists.First().FulleName; Genre genre = objEntity.Genres.FirstOrDefault(); if (genre != null) { objMp3Tag.Genre = genre.DisplayName; } if (cover != null) { while (objMp3Tag.PictureList.Any()) { objMp3Tag.PictureList.Remove(objMp3Tag.PictureList[0]); } IAttachedPicture picture = objMp3Tag.PictureList.AddNew(); if (picture != null) { picture.PictureData = cover; picture.PictureType = PictureType.CoverFront; // optional } } objMp3Tag.Save(file.FullName); } break; case ".flac": case ".flc": FlacTagger flacTaggerTag = new FlacTagger(file.FullName); flacTaggerTag.Album = objEntity.Album; flacTaggerTag.Artist = objEntity.Artists.First().FulleName; flacTaggerTag.Performer = objEntity.Artists.First().FulleName; Genre musicGenre = objEntity.Genres.FirstOrDefault(); if (musicGenre != null) { flacTaggerTag.Genre = musicGenre.DisplayName; } if (cover != null) { while (flacTaggerTag.Arts.Any()) { flacTaggerTag.RemoveArt(flacTaggerTag.Arts[0]); } ID3PictureFrame picture = new ID3PictureFrame(cover, ID3PictureType.FrontCover); flacTaggerTag.AddArt(picture); } flacTaggerTag.SaveMetadata(); break; } } } } } }