protected override void SetPicture(TagLib.File file, Tag tag) { TagLib.Ogg.File oggFile = (TagLib.Ogg.File)file; GroupedComment groupedCommentTag = (GroupedComment)tag; if (string.IsNullOrWhiteSpace(CoverFilePath)) { return; } // Is there a way to get Ogg file header using TagLib#? PropertyInfo headerProp = oggFile.GetType().GetProperty("LastPageHeader", BindingFlags.Instance | BindingFlags.NonPublic); PageHeader header = (PageHeader)headerProp.GetValue(oggFile); // Add cover art to Vorbis Comment approved METADATA_BLOCK_PICTURE field. TagLib.Flac.Picture pic = new TagLib.Flac.Picture(new Picture(CoverFilePath)) { Description = "" }; ByteVector picData = pic.Render(); XiphComment xiphComment = groupedCommentTag.GetComment(header.StreamSerialNumber); xiphComment.SetField("METADATA_BLOCK_PICTURE", Convert.ToBase64String(picData.Data)); }
/// <summary> /// Constructs and initializes a new instance of <see /// cref="File" /> for a specified file abstraction and /// specified read style. /// </summary> /// <param name="abstraction"> /// A <see cref="IFileAbstraction" /> object to use when /// reading from and writing to the file. /// </param> /// <param name="propertiesStyle"> /// A <see cref="ReadStyle" /> value specifying at what level /// of accuracy to read the media properties, or <see /// cref="ReadStyle.None" /> to ignore the properties. /// </param> /// <exception cref="ArgumentNullException"> /// <paramref name="abstraction" /> is <see langword="null" /// />. /// </exception> public File(File.IFileAbstraction abstraction, ReadStyle propertiesStyle) : base(abstraction) { Mode = AccessMode.Read; try { tag = new GroupedComment(); Read(propertiesStyle); TagTypesOnDisk = TagTypes; } finally { Mode = AccessMode.Closed; } }