Exemplo n.º 1
0
        public void DemoBasicUsageForID3v1()
        {
            // Create a new ID3v1 tag.
            ID3v1Tag v1Tag = new ID3v1Tag();

            v1Tag.Album       = "My Track Album";
            v1Tag.Artist      = "My Track Artist";
            v1Tag.Comments    = "My Track Comments";
            v1Tag.Genre       = "Rock";       // this has to be a genre from the ID3v1 genre list (see ID3Genre.cs)
            v1Tag.Title       = "My Track Title";
            v1Tag.TrackNumber = 1;
            v1Tag.Year        = "2004";

            // Write our new tag out to a file as ID3v1.1 (for example; v1.0 would work too)
            v1Tag.WriteTag("basic.tag", ID3Versions.V1_1);

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

                // Some usage possibilities:
                Console.WriteLine("Album: " + v1Tag.Album);
                if (v1Tag.HasArtist)                   // checks to see if Artist isn't null or empty
                {
                    Console.WriteLine("Artist: " + v1Tag.Artist);
                }

                // Make a change and write it back out to the file.
                v1Tag.Comments = null;
                v1Tag.WriteTag("basic.tag", ID3Versions.V1_1);

                // Show that the change worked.
                v1Tag = ID3v1Tag.ReadTag("basic.tag");
                if (v1Tag.HasComments)
                {
                    Console.WriteLine("Hmmmm....something didn't go right here.");
                }
                else
                {
                    Console.WriteLine("See! This library really does work.");
                }
            }
        }