Sub LogMp3Tags(Dir As String, FileName As String)
Private raf As RandomAccessFile
raf.Initialize2(Dir, FileName, True, True)
lblSongTitle.Text = ""
lblSongArtist.Text = ""
lblSongAlbum.Text = ""
lblSongYear.Text = ""
lblSongComment.Text = ""
lblSongGenre.Text = ""
If raf.Size < 128 Then
' Log("No TAG found.")
Return
End If
Private buffer(128) As Byte
raf.ReadBytes(buffer, 0, 3, raf.Size - 128)
If BytesToString(buffer, 0, 3, "UTF8") <> "TAG" Then
' Log("No TAG found.")
Return
End If
'Title
raf.ReadBytes(buffer, 0, 30, raf.CurrentPosition)
lblSongTitle.Text = ConvertBytesToString(buffer, 30)
'Artist
raf.ReadBytes(buffer, 0, 30, raf.CurrentPosition)
lblSongArtist.Text = ConvertBytesToString(buffer, 30)
'Album
raf.ReadBytes(buffer, 0, 30, raf.CurrentPosition)
lblSongAlbum.Text = ConvertBytesToString(buffer, 30)
'Year
raf.ReadBytes(buffer, 0, 4, raf.CurrentPosition)
lblSongYear.Text = ConvertBytesToString(buffer, 4)
'Comment
raf.ReadBytes(buffer, 0, 30, raf.CurrentPosition)
Private txt As String
txt = ConvertBytesToString(buffer, 30)
lblSongComment.Text = txt
'Genre
Private genre As Int
genre = raf.ReadUnsignedByte(raf.CurrentPosition)
If genre < 255 Then
lblSongGenre.Text = genre
End If
End Sub
Sub ConvertBytesToString(Buffer() As Byte, MaxLength As Int) As String
For i = 0 To MaxLength - 1
If Buffer(i) = 0 Then Return BytesToString(Buffer, 0, i, "UTF8")
Next
Return BytesToString(Buffer, 0, MaxLength, "UTF8")
End Sub