The MP3 tag is stored in the last 128 bytes of the file. The following code
will retrieve it for you:
Public Type MP3Info
Tag As String * 3
Songname As String * 30
Artist As String * 30
AlbumTitle As String * 30
AlbumYear As String * 4
Comment As String * 30
Genre As String * 1
Track As String * 1
End Type
Function GetMP3Info(FullPathToFile As String) As MP3Info
' This code was originally written by
' Doug Steele, MVP (e-mail address removed)
On Error GoTo Err_GetMP3Info
Dim intFreeFile As Integer
intFreeFile = FreeFile
Open FullPathToFile For Binary As intFreeFile
With GetMP3Info
Get #intFreeFile, FileLen(FullPathToFile) - 127, .Tag
If .Tag = "TAG" Then
Get #intFreeFile, , .Songname
Get #intFreeFile, , .Artist
Get #intFreeFile, , .AlbumTitle
Get #intFreeFile, , .AlbumYear
Get #intFreeFile, , .Comment
Get #intFreeFile, , .Genre
.Songname = TrimNull(.Songname)
.Artist = TrimNull(.Artist)
.AlbumTitle = TrimNull(.AlbumTitle)
.AlbumYear = TrimNull(.AlbumYear)
.Track = Mid$(.Comment, 30, 1)
.Comment = TrimNull(.Comment)
.Genre = TrimNull(.Genre)
End If
End With
End_GetMP3Info:
Close intFreeFile
Exit Function
Err_GetMP3Info:
Err.Raise Err.Number, "GetMP3Info", Err.description
Resume End_GetMP3Info
End Function
Function TrimNull(InputString As String) As String
' This code was originally written by
' Doug Steele, MVP (e-mail address removed)
On Error GoTo Err_TrimNull
Dim intNull As Integer
intNull = InStr(InputString, Chr(0))
If intNull > 0 Then
TrimNull = Left(InputString, intNull - 1)
Else
TrimNull = InputString
End If
End_TrimNull:
Exit Function
Err_TrimNull:
Err.Raise Err.Number, "TrimNull", Err.description
Resume End_TrimNull
End Function
An example of how to use this code would be:
Sub RetrieveMP3Tag()
Dim strFileName As String
Dim typMP3Tag As MP3Info
strFileName = "C:\My Music\MyMP3File.mp3"
typMP3Tag = GetMP3Info(strFileName)
With typMP3Tag
If .Tag = "TAG" Then
Debug.Print "Song Name = " & .Songname
Debug.Print "Artist = " & .Artist
Debug.Print "AlbumTitle = " & .AlbumTitle
Debug.Print "AlbumYear = " & .AlbumYear
Debug.Print "Track Number = " & Asc(.Track)
Debug.Print "Comment = " & .Comment
Else
Debug.Print "File did not include MP3 tag"
End If
End With
MsgBox strMessage
End Sub
Genre is a one-byte field that points to a list of categories. To see its
value, use Asc(.Genre). However, the list is of questionable value (it's
kind of old, and subjective), so I won't bother posting it here.