Perry’s ID3 Tag Library

ID3v2Perry’s ID3 Tag Library is a free open-source ID3v1 and ID3v2 tag parsing utility for MP3 files that has been tested to work with Visual Studio, VB.NET, ASP.NET, Visual Basic for Applications and VBScript.

Use the library as a reference in your own Visual Studio project to parse ID3 tag data embedded in MP3 files, or use the ActiveX control to give familiar Microsoft Office products such as Word and Excel the ability to parse ID3 tags. This library is useful for anyone looking to implement ID3 tag capabilities in their own custom solutions and applications.

You might be interested in Perry’s ID3 Tag Viewer which is a full implementation of the current ID3 Tag Library version.

Tag Writing is currently in the works as of May 2012!

The ID3TagLibrary is pretty simple to use:


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  ' create an mp3 object from a file on the hard drive
  Dim mp3 As New ID3TagLibrary.MP3File("C:\song.mp3")
  ' put the mp3's title into a label control
  Label1.Text = mp3.Title
  ' put the mp3's artwork (if any!) into a picturebox control
  PictureBox1.Picture = mp3.Tag2.Artwork
End Sub

News

  • September 13, 2013 – Version 0.4 is now on Github! I recently started experimenting with MPEG header frame parsing which will make information available such as song duration, bitrate, sampling rate, etc.
  • September 9, 2013 – New version 0.4 is here! Jump to the Downloads.
  • May 30, 2012 – So writing ID3v2 tags is a more formidable opponent than I first realized, but that’s not to say I haven’t made tons of progress! Version 0.3 could read tags just fine, but the code I wrote to do that was fairly lightweight and it skipped over some of the deeper ID3v2 data and details such as text encoding and padding bytes. As it turns out, I now need to consider those details in order to write out the tags correctly so they are compatible. This means having a solid understanding of low level computer science concepts like bits, hex, binary and unicode, which I did not have a firm grasp on until last week! There are even more considerations here like having to split and rejoin the file when a frame’s value is modified to something larger than the frame’s original size, and preserving the text encoding used for modified text frames. I have some very promising code in the works that I’ve been writing tags successfully with, but I have a few bugs to iron out (written tags show some corrupt data Winamp) and some code to tidy up before releasing a new version.
  • May 23, 2012 – Tag writing works in development! I can now change a frame’s text value or picture (album art) and save it, but only if the frame doesn’t need to be enlarged. Enlargement will require splitting and rejoining the file, so I still need to develop that. Stay tuned for v0.4…
  • May 22, 2012 – due to the rising interest in this library and several feature requests, I’ve started implementing ID3 tag writing. I have a great prototype in the works for writing tags which I think even the most seasoned power users will enjoy. You can also expect many of the workarounds and bugs mentioned in the comments section here on this page before May 2012 to be ironed out in the next version release. As usual, I’ll also release a new version of the ID3 Tag Viewer which implements these changes.
  • July 20, 2011 – version 0.3 released.
  • April 19, 2011 – version 0.2 released.
  • March 28, 2011 – version 0.1 released.

Features

  • Parse ID3v1 and ID3v2 (ID3 2.2, ID3 2.3, ID3 2.4) tag data, including most/all frames outlined in the official ID3 spec.
  • Embedded picture frames (APIC) are converted to native System.Drawing.Image objects for ease of access.

System Requirements

  • Visual Studio, VBScript or VBA

Screenshots

Coming soon!

Downloads

Instructions

Visual Studio Usage Example

This example will show you how to use the ID3TagLibrary natively in an existing project.

  1. Extract the Visual Studio project from the SOURCE download to your computer.
  2. Open Visual Studio and create a new host project that will utilize the ID3TagLibrary. Choose the VB.NET Windows Forms Application project template. By default this will be named  WindowsApplication1.
  3. Add an existing project (File > Add > Existing Project). Browse to the ID3TagLibrary.vbproj file and open it. Since you now have two projects, Visual Studio creates a top level Solution file in the Solution Explorer, and the two projects appear beneath this.
  4. In the Solution Explorer, select the host project (WindowsApplication1) and add a reference to the ID3TagLibrary (Project > Add Reference).
  5. When the Add Reference dialog appears, click the Projects tab, select the ID3TagLibrary then click OK.
  6. Open the code window for Form1 in the host project (WindowsApplication1). In the Form_Load event, write the following code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim myMP3 As New ID3TagLibrary.MP3File(“C:\test.mp3”)
    MessageBox.Show(myMP3.Artist)
    End Sub
  7. Run the WindowsApplication1 project (F5 or Debug > Start Debugging). When the blank Form1 appears, it should show a MessageBox with the Artist name from the MP3’s ID3 tag.

VBScript Usage Example

This example will show you how to use the ID3TagLibrary through VBScript.

  1. Save the dynamic link library ID3TagLibrary.dll file to your computer.
  2. Register the ID3TagLibrary.dll file on your computer using REGASM:
    1. Open a command prompt (Start > All Programs > Accessories > Command Prompt) and navigate to the directory where you saved the ID3TagLibrary.dll file. For example, if you saved it to the desktop you would type:
      cd %userprofile%\desktop
    2. Then execute the following REGASM command:
      %windir%\microsoft.net\framework\v2.0.50727\regasm ID3TagLibrary.dll /codebase
  3. Create a new text file and rename it to VBScript.vbs.
  4. Open VBScript.vbs in NotePad and code a reference to the ID3TagLibrary’s ComParser interface and access some MP3 file info:
    Set myParser = CreateObject(“ID3TagLibrary.ComParser”)
    MsgBox myParser.ParseMP3(“C:\test.mp3”).Artist
  5. Save and close the VBScript file, then double click the file to execute it. It should show a MessageBox with the Artist name from the MP3’s ID3 tag.

Microsoft Access 2002 Usage Example

This example will show you how to use the ID3TagLibrary in a Microsoft Access file.

  1. Save the type library ID3TagLibrary.tlb file to the client computer.
  2. In Access, open the Visual Basic Editor (Tools > Macros > Visual Basic Editor). In the Visual Basic Editor, open the References dialog (Tools > References).
  3. Click Browse and locate the ID3TagLibrary.tlb file. Click Open; the ID3TagLibrary is added to the list of Available References, with a checkmark. Click OK to close the References dialog.
  4. In the Visual Basic Editor, insert a new module (Insert > Module).
  5. In the Module1 (Code) window, code a Sub for testing our COM interop and access some MP3 file info:
    Sub TestComInterop()
    Set myParser = New ID3TagLibrary.ComParser
    MsgBox myParser.ParseMP3(“C:\test.mp3”).Artist
    End Sub
  6. Place your cursor in the TestComInterop Sub and execute it (F5 or Run > Run Sub/Userform). It should show a MessageBox with the Artist name from the MP3’s ID3 tag.

Want to see a full list of properties and methods? Just open the Object Browser in Visual Studio and navigate the ID3Library:

Object Browser

More documentation coming soon…

Disclaimer

All of my software comes with the same disclaimer. I do test and use my own software programs, and while I’m pretty confident there are no dire consequences to using them, I can’t be held liable for any damage caused by the use of my software, whether due to bugs, unforseen functionality or any other reason. I always recommend that you test my software on a sample before attempting the real thing. This will give you an idea of how it works and what to expect. Thank you for your interest in my software!

Related

Tags: , ,

119 Comments

  1. Hi. I have a question about your library. What encoding are you using when parsing all of the track information?
    I am having difficulties getting your library to show titles including “special characters” (æ ø å é and so on)

    • José Abascal says:

      Hi Martin,

      I’m from Chile and we have a lot of special chars to handle.

      You have to download latest source code.

      Open it with Visual Studio.

      Locate File : Globals.vb

      Look for ” BytesToText ” Function

      and replace encoding type from ASCII to Unicode

      Here is the fixed code

      I hope it works for you

      ”’
      ”’ Converts an array of Bytes to a String, optionally removing non-alphanumeric characters.
      ”’
      ”’
      ”’
      ”’
      ”’
      Function BytesToText(ByVal argBytes() As Byte, ByVal argRemoveNonAlphanumeric As Boolean) As String
      Dim mText As String = “”
      Dim lst As New ArrayList(argBytes)
      Dim x() As Byte
      x = Array.FindAll(argBytes, AddressOf isAlphaNumeric)

      ”’mText = Text.Encoding.Unicode.GetString(x) ‘ ORIGINAL ENCODING

      mText = Text.Encoding.Unicode.GetString(x) ‘ FIX SPECIAL CHARS

      Return mText
      End Function

      Then Save

      And Rebuild

      Saludos!!!!!

  2. I see the ability to write new tag info as secondary to simply releasing the resources. I have a feeling a few of us are using this to read an MP3 collection and re-write the filenames to our own standard. When I get MP3s from other sources they’re often named in a “less than optimal” way for me so I was using this to read the file’s tag info and rename the files and create M3Us. I tried simply setting the object to Nothing (VB.Net) or re-using the same object variable but no luck.

    • Paul, as you know I recently replied to your email about the locked files. I believe this has been fixed in the latest development version (per my tests), which I’ve sent to you for your own testing purposes. As soon as I get some feedback for this version I will determine whether or not to release it publicly. Stay tuned folks!

      By the way, the file locks were happening in both the ID3v1Tag.vb module Sub New() and the ID3v2Tag.vb module Sub ParseTag(). In both of these subroutines, we were opening a file stream without closing or disposing the object at the end of the routine – mReader.Close()/mReader.Dispose() and gTagReader.Close()/gTagReader.Dispose(). Hope that helps someone out there.

  3. Hi Perry,
    have searched a long time for a good ID3-Tag-Library to use it with my new Windows 8.1 system with MS-Access (VBA). Installation was done as shown under “MS-Access 2002 Usage”.

    Unfortunately it doesn’t work and shows error message 429 “Object creation is impossible by ActiveX component”.

    Have checked your .dll by tool “depends.exe” and found some error messages.

    Can you help me ?

    Cheers
    RedFox

  4. Claudio54 says:

    hi Perry

    ihow con use ID3TagLibrary to extract artwork in mp3 with vba excel 2010.
    i’m in fance and i write very bad English.

    can you help me ?

  5. Love your Tag reader, being giving create results. I’m now trying to write the tags, can you let me know if 1: It is possible with your .dll and 2: How.

    Keep up the great work, I love it.

    Look forward to hearing from you.

  6. Richard Evans says:

    Thank you for ID3 work. Your code is readable and easy to follow. Some others require a debugger to understand.

    It was reassuring to see your confirmation of WMP using an unconventional mechanism for storing images. I was aware they “did their own thing” from past issues similar to what you describe, but didn’t realize how far from the standard they’d gone, using PRIV frames for their own purposes. However, if you can’t beat ’em…

    For my own project would like to use the embedded Microsoft image, if one exists. I’ve been poking and prodding at the PRIV data trying to get lucky, but have reached the point of exhaustion where it would be easier to ask. Have you (or anyone else reading) figured a method to extract those AlbumArt images?

    Regards,

    • Windows Media Player has an online repository of known music to make tagging your own music easier and automatic. When a song is auto-tagged using the online repository, Windows Media Player will store a unique ID in the MP3 file’s ID3 tag. Windows Media Player will also generate hidden AlbumArt images in the same folder as the MP3 files, with filenames containing that same unique ID. So when you play a song, Windows Media Player seems to get the unique ID from the PRIV frame, then match that to the hidden AlbumArt images, bringing the song and artwork together as one discreet unit in Windows Media Player, even though the two are separate and only loosely related based on that unique ID.

      The problem arises when two songs or albums somehow contain the same unique ID in the PRIV frames. Windows Media Player will treat both songs or albums as having the same AlbumArt, and you will start seeing the wrong AlbumArt for some files. This is due to the PRIV frames not containing a correct unique ID, I believe. Sometimes WMP will save the unique ID as all zeros. You may end up with several, and this makes the AlbumArt situation really bad over time.

      Most other software will embed the AlbumArt inside the MP3 file via the ID3 tag, allowing for greater portability since the art will always stay with the music file. Windows Media Player does not seem to do this, and instead uses loose AlbumArt image files.

      To hopefully answer your question, you just need to show hidden files and folders to see the AlbumArt that has been generated by Windows Media Player.

  7. i try your .dll ad implement to my program,,,but when i try to read about 200 mp3 files ,,,my computer got freeze up,,,please tell me what happen,,,

  8. i try your .dll and implement to my program,,,but when i try to read about 200 mp3 files ,,,my computer got freeze up,,,please tell me what happen,,,

  9. Hello,

    fantastic, but i have a question:
    is it possible to read the field albumartist ?
    bye Klaus

    • Hi Klaus,

      i has the same question, but i develop the Album Artist property by myself. The Problem is that the Album Artist is not a standard in ID3 Tags. For me i used the TPE2 tag for reading Album Artist in ID3v2.x.
      In the Code i add to the Class ID3v2Tag a new Function, based on Artist, named AlbumArtist and changed GetFrameValue(“TPE2”). And second add a property in class MP3File named AlbumArtist. Then i read only in ID3v2 the new property AlbumArtist.
      I don’t tested mp3 files from different Players, Librarys. But i work for tagging with Mp3Tag application, all my files i can read the AlbumArtist.

  10. Christopher-Michael says:

    I want to thank you for this library! Got it set up in VBStudio 2013 with only minor hassle haha One Issue I am running into when passing the mp3 files from the parent directory containing all mp3s is that I’ve run into an System.OverflowException which if I recall correctly pointed to this line: Dim mSizeV3 As Integer = GetID3EncodedSizeV3(mFrameSizeBytes). Now, using a tag editor and having it scan all of my mp3 files and then resaving them all…without editing a single tag out of the thousands of files, I can run my program without a problem. My issue is that I have been trying to catch the overflow exception and print a messagebox to inform the user that there is an issue with the tags of at least one of their files and how they can easily fix it with an external tag editor. This, of course, will keep my program from crashing completely and inform them of how to fix the error. My program currently does not do anything with tags other than reading them but even if I were to eventually add tag writing/saving operations which could fix whatever the problem is that popped up, I would need to catch the exception so that the program doesn’t crash and the user knows how to fix the problem. I’ve added Try/Catch/End Try to your files which did not seem to fix the issue and then I tried adding them to my code and the problem still persisted. It only went away and the program completed its operation once I resaved all of the mp3 files. I am not sure if anyone has any ideas of how to either fix this problem or at least catch it within the ID3 Library or within my own code. I greatly appreciate any ideas =0)

    • Hi Christopher-Michael, I’m glad you were able to get some usage out of it, if only partially! I haven’t visited this code library in over 2 years, but it really taught me a lot about low level programming and I think one day I will return to fix up the bugs and finish out the tag writing capability, which last time I checked was half-way done. It seems to me like there’s still a robust community for VB since this article remains one of my most viewed 🙂

      The error you’re getting could be due to a bad algorithm in the GetID3EncodedSizeV3, but I can’t say for sure without doing some tests. What I would recommend is trying to view your “bad” files in Perry’s ID3 Tag Viewer to see if the same error occurs. I’m not sure, but I think the Tag Viewer might use newer (unreleased) version of the library. Failing this, I would definitely like for you to send me one of your “bad” mp3’s so I may debug it on my end when I do get a chance.

    • Christopher-Michael says:

      Sure! I fixed the ‘bad’ files. I did not use your tag viewer but used TagScanner. TagScanner did not throw up any errors in showing me any files/tags but then I simply selected all and resaved the files without making any changes and it seemed to fix whatever made your library throw errors but not TagScanner. I will download your tag viewer and if I run into this problem with any future files i will check to see if your viewer has an issue with it. Either way I could send you a copy of the ‘problem’ file. My main concern was trying to catch the exception so I can at least keep the program from crashing and let any users know how to fix this issue. But I have not yet successfully captured the error programmatically. I guess if the problem persists I will warn eventual users of my program that if this error occurs that they should use an external app and simply resave all files.

    • Thanks for writing back. Here’s what I think is happening. The ID3 Tag Library (and Viewer) will read EVERY frame in the ID3v2 tag per the official spec. Each frame in the ID3v2 tag contains a size (in bytes) that allows us to know how big the frame is, but more importantly where the next frame is in the tag. A correctly written tag should be able to have all frames read by sequentially parsing each frame’s size. Most other tag editors and music programs don’t do this and will instead do a string search for common frame types like album, artist, etc. So there could be an incorrectly written frame in your “bad” files which is simply being ignored by other software since they aren’t even attempting to parse the whole tag. Now the reason I think this is the case without even debugging your file is because of the fact that you said re-saving the file without changing anything fixed the problem. Usually in other ID3 tagging software, re-saving the file will strip the original tag and re-write a new tag containing only the frames which that software was able to read. To test this theory, you should check if the file size (in bytes) changed after re-saving it in TagScanner, which might indicate the tag was re-written.

      But to be sure, definitely send me one of your “bad” files so I can run it through the Viewer and also a debugger so I can take a look at the raw frame data. My email is perry@glassocean.net.

    • Christopher-Michael says:

      I appreciate your looking into this further and the logic seems sound to me! Every time I procure more files I run my application I am currently working on to include newly added files so as soon as I come across a single file that throws this exception I will make a copy of it and ‘fix’ one of the copies so that I can actually use it but keep the perhaps malformed ID3 tagged file for you to check out.

      I am still trying to figure out how to catch the exception properly and perhaps report back to the user which specific files caused the problems. Then they could load just those offending files into a tagging app rather than being told that a file or multiple files had issues which can be fixed by simply scanning their whole mp3 collection into the app and then saving them all. But that part isn’t mandatory. Just trying to properly catch the exception and report with a mssgbox that this is, in fact, the problem they are experiencing and how to fix it. I will continue to work on that as I do not want my program crashing and leaving the user clueless. But as soon as I find another offending file I will send it to you and also do a little investigating work myself as you suggested with before/after ‘fixing’ file sizes and the like. Good work man!

  11. How can I convert genre number in genre string?

  12. Hi, Perry

    Thanks for great library.

    I made a function if mp3 tag has cover image or not.

    When I execute, it makes error of Parameter is not valid.

    How can I check if image is valid?

    —————————
    Private Function HasImgInTag(ByRef tPath As String) As Boolean

    HasImgInTag = False

    If tPath “” Then
    Dim myMP3 As New ID3TagLibrary.MP3File(tPath)

    If Not IsNothing(myMP3) Then

    ‘below line makes Parameter is not valid error when image doesn’t exist
    Dim img As Image = myMP3.Tag2.Artwork(100)

    If Not img Is Nothing Then
    HasImgInTag = True
    End If

    End If
    End If
    Return HasImgInTag

    End Function

  13. Tried the tlb file in Access 2003. Received error 429 (Activex cannot create object). Is there a solution to this issue?

  14. Special characters fix:
    José Abascal method didn’t work – produces empty labels/strings.

    Locate -> Function BytesToText

    comment new method
    uncomment old method

    The old method appears to work, now i can see the character “á” instead of “-“

  15. mark donners says:

    I have a question about the artwork …..in your example picturebox1.picture–> i had to change it to picturebox1.image..
    But how to use the tag2.artwork(1) What number has to be between the brackets..i used 0 to 100 but i dont see any changes…what does it do?

    Private Sub Button3_Click_1(sender As Object, e As EventArgs) Handles Button3.Click
    Dim myMP3 As New ID3TagLibrary.MP3File(“C:\test.mp3”)
    MessageBox.Show(myMP3.Title)
    PictureBox1.Image = myMP3.Tag2.Artwork(0)
    PictureBox1.BackgroundImageLayout = ImageLayout.Zoom
    PictureBox1.Visible = True
    End Sub

  16. How can I save the MP3 files back to HDD when edited the IDTag?!?

  17. I have a memory problem in cycle for each.

    For Each Archivo As String In My.Computer.FileSystem.GetFiles(StorePath, FileIO.SearchOption.SearchAllSubDirectories, “*.mp3”)

    Dim mp3 As New ID3TagLibrary.MP3File(Archivo)

    ListBox.Items.Add(mp3.Artist)
    End With
    Next

    This causes an error – > “System.OutOfMemoryException”

Leave a Reply

Your email address will not be published. Required fields are marked *