Get tag info form a mp3 file

Level:
Level1

Since Visual Basic has great support for reading and writing to the file system it can be used for things that wern't even popular or around when it was created. A great example of this is MP3 files. This source code sample show how you can read the file information details from an MP3 file and grab any of the tag info from that audio file. The tagging info are things such as Title, Artist, Album, Year, and Custom Comment information. These are set in programs such as iTunes. (E6ZXKMNDB23T)

To use this source snippet simply create a new VB6 project. Add five text boxes to the form. Open up the code for the form and add the following source code:

  1. Private Type Mp3Tag
  2.     Title As String * 30
  3.     Artist As String * 30
  4.     Album As String * 30
  5.     Year As String * 4
  6.     Comment As String * 30
  7. End Type
  8.  
  9. Private Sub Form_Load()
  10.         Dim TagInfo As Mp3Tag
  11.         Dim FileNum As Integer
  12.         Dim Tag As String * 3
  13.         FileNum = FreeFile
  14.                 Open "c:\Demo.mp3" For Binary As FileNum
  15.                 Seek #FileNum, LOF(FileNum) - 127
  16.                 Get #FileNum, , Tag
  17.         If Tag = "TAG" Then
  18.                 Get #FileNum, , TagInfo.Title
  19.                 Get #FileNum, , TagInfo.Artist
  20.                 Get #FileNum, , TagInfo.Album
  21.                 Get #FileNum, , TagInfo.Year
  22.                 Get #FileNum, , TagInfo.Comment
  23.         End If
  24.         Close #FileNum
  25.  
  26.         Text1.Text = Trim(TagInfo.Title)
  27.         Text2.Text = Trim(TagInfo.Artist)
  28.         Text3.Text = Trim(TagInfo.Album)
  29.         Text4.Text = Trim(TagInfo.Year)
  30.         Text5.Text = Trim(TagInfo.Comment)
  31.  
  32. End Sub

Obviously this code snippet is hard coded to only read Demo.mp3 on the C drive, but you could easily modify it to hit a different file or to even allow the user to select the file. Also you could even use the knowledge you can glean from this to change MP3 tagging info. If you do this please add a comment below and share with everyone what fun Visual Basic mp3 tricks you come up with.

Note: The source for this was found at DreamVB which is no longer online. (E6ZXKMNDB23T)

If you enjoyed this post, subscribe for updates (it's free)

Issue

Hey thanks a lot for this code. However when i create a new forms application, add five textboxes and add the code (except Private Sub Form_Load()) and change the directory to an existing one, i still get many errors? If you can make additional tut or give me a link for the project folder, Ill join the site.
Thanks