示例#1
0
		public void ValidationOKTest()
		{
			/*
             *  T___
             *  TXXX
             *  WXXX
             *  APIC
             */

			var tagContainer = new TagContainerV3();
			tagContainer.Tag.SetExtendedHeader(0, false);
			tagContainer.Tag.SetHeaderFlags(false, false, false);

			var textFrame = new TextFrame("TALB", "My Albun", Encoding.Default);
			var userDefineTextFrame = new UserDefinedTextFrame("my comment", "so", Encoding.Default);
			var linkFrame = new UserDefinedURLLinkFrame("id3tag", "id3tag.codeplex.com", Encoding.Default);
			var pictureFrame = new PictureFrame(
				Encoding.Default,
				"image/jpeg",
				"la",
				PictureType.Other,
				new byte[] { 0x11, 0x12, 0x13, 0x14 });

			tagContainer.Add(textFrame);
			tagContainer.Add(userDefineTextFrame);
			tagContainer.Add(linkFrame);
			tagContainer.Add(pictureFrame);

			WriteTagContainer(tagContainer);

			// OK... passed!
		}
示例#2
0
        public void ConstructorTest()
        {
            var encoding = Encoding.Default;
            const string mime = "ABCD";
            const string description = "EFGH";
            const PictureType pictureType = PictureType.Other;
            var pictureData = new byte[] {0x20, 0x21, 0x22, 0x23};

            var frame = new PictureFrame(encoding, mime, description, pictureType, pictureData);

            Assert.AreEqual(frame.TextEncoding.CodePage, encoding.CodePage);
            Assert.AreEqual(frame.MimeType, mime);
            Assert.AreEqual(frame.Description, description);
            Assert.AreEqual(frame.PictureCoding, pictureType);
            Assert.IsTrue(ComparePayload(frame.PictureData, pictureData));
        }
示例#3
0
        public void ConvertISO8859()
        {
            var encoding = Encoding.Default;
            const string mimeType = "ABCD";
            const PictureType pictureType = PictureType.CoverFront;
            const string description = "EFGH";
            var data = new byte[] {0x20, 0x21, 0x22, 0x23};

            var pictureFrame = new PictureFrame(encoding, mimeType, description, pictureType, data);
            var rawFrame = pictureFrame.Convert(TagVersion.Id3V23);

            var refBytes = new byte[]
                               {
                                   0x00, 0x41, 0x42, 0x43, 0x44, 0x00, 0x03, 0x45, 0x46, 0x47, 0x48, 0x00,
                                   0x20, 0x21, 0x22, 0x23
                               };

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
示例#4
0
        public void ConvertUTF16()
        {
            const TextEncodingType encoding = TextEncodingType.UTF16;
            const string mimeType = "ABCD";
            const PictureType pictureType = PictureType.CoverFront;
            const string description = "EFGH";
            var data = new byte[] {0x20, 0x21, 0x22, 0x23};

            var pictureFrame = new PictureFrame(encoding, mimeType, description, pictureType, data);
            var rawFrame = pictureFrame.Convert();

            var refBytes = new byte[]
                               {
                                   0x01, 0x41, 0x42, 0x43, 0x44, 0x00, 0x03, 0xFF, 0xFE, 0x45, 0x00, 0x46, 0x00, 0x47,
                                   0x00, 0x48, 0x00, 0x00, 0x00,
                                   0x20, 0x21, 0x22, 0x23
                               };

            Assert.IsTrue(ComparePayload(rawFrame.Payload, refBytes));
        }
示例#5
0
        public void ValidationPictureFrameFailed1()
        {
            /*
             *  T___
             *  TXXX
             *  WXXX
             *  APIC
             */

            var tagContainer = new TagContainer();
            tagContainer.Tag.SetExtendedHeader(0, false);
            tagContainer.Tag.SetHeaderFlags(false, false, false);
            tagContainer.Tag.SetVersion(3, 0);

            var textFrame = new TextFrame("TALB", "My Albun", TextEncodingType.ISO_8859_1);
            var userDefineTextFrame = new UserDefinedTextFrame("my comment", "so", TextEncodingType.ISO_8859_1);
            var linkFrame = new UserDefinedURLLinkFrame("id3tag", "id3tag.codeplex.com", TextEncodingType.ISO_8859_1);
            var pictureFrame = new PictureFrame(TextEncodingType.UTF16_BE, "image/jpeg", "la", PictureType.Other,
                                                new byte[] { 0x11, 0x12, 0x13, 0x14 });

            tagContainer.Add(textFrame);
            tagContainer.Add(userDefineTextFrame);
            tagContainer.Add(linkFrame);
            tagContainer.Add(pictureFrame);

            WriteTagContainer(tagContainer);

            // OK... passed!
        }
示例#6
0
        private static void WritePictureFrame(ID3V2TagData data, TagContainer 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);
            }
        }
示例#7
0
        private void ShowPicture(PictureFrame pictureFrame)
        {
            labelMimeType.Content = pictureFrame.MimeType;
            labelTextEncoding.Content = pictureFrame.TextEncoding;
            labelDescription.Content = pictureFrame.Description;
            labelPictureType.Content = pictureFrame.PictureCoding;

            var bytes = pictureFrame.PictureData;
            try
            {
                Stream pictureStream = new MemoryStream(bytes);

                var bitmap = new BitmapImage();
                bitmap.BeginInit();
                bitmap.StreamSource = pictureStream;
                bitmap.EndInit();

                imagePicture.Source = bitmap;
            }
            catch (Exception ex)
            {
                throw new ID3TagException("Cannot read the picture frame : " + ex.Message);
            }
        }
示例#8
0
 private static IFrame AnalyseFrameId(RawFrame rawFrame)
 {
     IFrame frame;
     if (rawFrame.ID[0] == 'T' || rawFrame.ID[0] == 'W')
     {
         switch (rawFrame.ID[0])
         {
             case 'T':
                 if (rawFrame.ID != "TXXX")
                 {
                     frame = new TextFrame();
                 }
                 else
                 {
                     frame = new UserDefinedTextFrame();
                 }
                 break;
             case 'W':
                 if (rawFrame.ID != "WXXX")
                 {
                     frame = new UrlLinkFrame();
                 }
                 else
                 {
                     frame = new UserDefinedURLLinkFrame();
                 }
                 break;
             default:
                 throw new ID3TagException("Unknown Text or URL frame!");
         }
     }
     else
     {
         // Other frames
         switch (rawFrame.ID)
         {
             case "AENC":
                 frame = new AudioEncryptionFrame();
                 break;
             case "PRIV":
                 frame = new PrivateFrame();
                 break;
             case "MCDI":
                 frame = new MusicCdIdentifierFrame();
                 break;
             case "COMM":
                 frame = new CommentFrame();
                 break;
             case "APIC":
                 frame = new PictureFrame();
                 break;
             case "PCNT":
                 frame = new PlayCounterFrame();
                 break;
             case "POPM":
                 frame = new PopularimeterFrame();
                 break;
             case "UFID":
                 frame = new UniqueFileIdentifierFrame();
                 break;
             default:
                 frame = new UnknownFrame();
                 break;
         }
     }
     return frame;
 }