Exemple #1
0
        public void DemoBasicUsageForID3v2()
        {
            // Create a new ID3v2 tag. ID3v2 works mostly like ID3v1 from this
            // perspective, although there are a few enhancements we can use.
            ID3v2Tag v2Tag = new ID3v2Tag();

            // no length restrictions with v2
            v2Tag.Album = "An album with a really long name that wouldn't fit into a ID3v1 tag";
            v2Tag.Genre = "A genre of my own creation!";             // not restricted to pre-defined genres with v2

            // Write our new tag out to a file as ID3v2.3 (for example; v2.2
            // and v2.4 would work too, although ID3v2.4 support is scare out
            // in the real world)
            v2Tag.WriteTag("basic.tag", ID3Versions.V2_3);

            // Read the tag back from the file.
            v2Tag = null;
            if (!ID3v2Tag.HasTag("basic.tag"))
            {
                Console.WriteLine("Hmmmm....something didn't go right here.");
            }
            else
            {
                v2Tag = ID3v2Tag.ReadTag("basic.tag");

                // Some usage possibilities:
                Console.WriteLine("Album: " + v2Tag.Album);

                // Make a change and write it back out to the file.
                v2Tag.Comments = "New comments";
                v2Tag.WriteTag("basic.tag", ID3Versions.V2_3);

                // Show that the change worked.
                v2Tag = ID3v2Tag.ReadTag("basic.tag");
                if (v2Tag.HasComments)
                {
                    Console.WriteLine("The comments we just added: " + v2Tag.Comments);
                }
                else
                {
                    Console.WriteLine("Hmmmm....something didn't go right here.");
                }

                // Some other stuff:
                ID3Versions version = ID3v2Tag.LookForTag("basic.tag");
                Console.WriteLine("ID3 tag found, version: " + version.ToString());
            }
        }