public TagDataDialog() { InitializeComponent(); Data = new ID3V2TagData { TextEncoding = Encoding.Default, Album = "My Album", Artist = "My Artist", Title = "My Title", Year = "2009", Comment = "", Unsynchronisation = false, ExperimentalIndicator = false, ExtendedHeader = false, CrCPresent = false, Crc = new byte[0], PaddingSize = 0 }; }
public TagContainer BuildTag(ID3V2TagData data) { TagContainer container = Id3TagFactory.CreateId3Tag(data.Version); if (data.Version == TagVersion.Id3V23) { // // Configure the ID3v2.3 header // TagDescriptorV3 extendedHeaderV23 = container.GetId3V23Descriptor(); // Configure the tag header. extendedHeaderV23.SetHeaderOptions(data.Unsynchronisation, data.ExtendedHeader, data.ExperimentalIndicator); if (data.ExtendedHeader) { extendedHeaderV23.SetExtendedHeader(data.PaddingSize, data.CrCPresent); extendedHeaderV23.SetCrc32(data.Crc); } } else { // // Configure the ID3v2.4 header // TagDescriptorV4 extendedHeaderV24 = container.GetId3V24Descriptor(); extendedHeaderV24.SetHeaderOptions(false, false, false, true); } // OK. Build the frames. var albumFrame = new TextFrame("TALB", data.Album, data.TextEncoding); var artistFrame = new TextFrame("TPE2", data.Artist, data.TextEncoding); var yearFrame = new TextFrame("TYER", data.Year, data.TextEncoding); var titleFrame = new TextFrame("TIT2", data.Title, data.TextEncoding); var textComment = new UserDefinedTextFrame("Your comment", data.Comment, data.TextEncoding); var comment = new CommentFrame("ENG", "Your Comment", data.Comment, data.TextEncoding); var encoder = new TextFrame("TENC", data.Encoder, data.TextEncoding); container.Add(albumFrame); container.Add(artistFrame); container.Add(yearFrame); container.Add(titleFrame); container.Add(textComment); container.Add(comment); container.Add(encoder); if (data.PictureFrameEnabled) { if (File.Exists(data.PictureFile)) { WritePictureFrame(data, container); } else { MessageBox.Show("Picture file not found."); } } if (data.WriteLyricsFlag) { WriteUnsychronisedLyrics(data.LyricsDescriptor, data.Lyrics, container); } return container; }
private static void WritePictureFrame(ID3V2TagData data, ICollection<IFrame> container) { using (FileStream stream = File.Open(data.PictureFile, FileMode.Open)) { // // Read the picture. // int byteCount = Convert.ToInt32(stream.Length); var pictureData = new byte[byteCount]; stream.Read(pictureData, 0, byteCount); // // Add the picture frame. // var pictureFrame = new PictureFrame( Encoding.Default, "image/jpg", "Other", PictureType.Other, pictureData); container.Add(pictureFrame); } }