I could not find a b4a library, which is able to extract images from mp3 files, and so I had to write my own class in pure b4a.
(My java knowledge is too limited to write a b4a wrapper for an existing library)
With this class it should be easy to read all metadata(Artist, Title etc.) and all attached images(Cover Art and other pictures)from a mp3 file.
Note that i have tested this class with my own mp3 files collection but it is not bullet-proof, there are a lot of different id3v2 versions and a lot of mp3 files containing "garbage" in the id3v2 tag.
This is an example for extracting the cover image:
This is an example for extracting all available metadata into a Listview:
UPDATE Version 1.1:
Fixed an error with older id3v2 versions (id3v2.2).
Currently this class reads id3v2.3 and id3v1 tags.
id3v2.4 tags are not fully supported.
id3v2.2 tags are not supported.
(My java knowledge is too limited to write a b4a wrapper for an existing library)
With this class it should be easy to read all metadata(Artist, Title etc.) and all attached images(Cover Art and other pictures)from a mp3 file.
Note that i have tested this class with my own mp3 files collection but it is not bullet-proof, there are a lot of different id3v2 versions and a lot of mp3 files containing "garbage" in the id3v2 tag.
This is an example for extracting the cover image:
B4X:
Dim ID3 as ID3
ID3.Initialize(myDir, myFile)
If ID3.hasPictures then
Dim bmp as Bitmap
bmp = ID3.Cover
'...do something with the cover bitmap
End if
This is an example for extracting all available metadata into a Listview:
B4X:
Sub ReadID3Tag (Dir As String, Filename As String)
Dim i As Int
Dim ID3 As ID3
Dim Frame As ID3_Frame
Dim Pic As ID3_Picture
Dim Comment As ID3_Comment
Dim Other As ID3_OtherData
'
ID3.Initialize(myFolder, myFile)
If ID3.Exists = False Then lv.AddTwoLines(myFile, "no ID3 Tag found.")
If ID3.version >= 3 Then 'id3v2.2 not supported
If ID3.hasPictures Then lv.AddTwoLinesAndBitmap(myFile, "", ID3.Cover)
lv.AddTwoLines("Title", ID3.Title)
lv.AddTwoLines("Artist", ID3.Artist)
lv.AddTwoLines("Album", ID3.Album)
lv.AddTwoLines("Genre", ID3.Genre)
lv.AddTwoLines("Track", ID3.Track)
lv.AddTwoLines("Comment", ID3.Comment)
lv.AddTwoLines("Copyright", ID3.Copyright)
lv.AddTwoLines("BPM", ID3.bpm)
'Get all attached pictures:
For i = 0 To ID3.Pictures.Size-1
Pic = ID3.Pictures.Get(ID3.Pictures.GetKeyAt(i))
lv.AddTwoLinesAndBitmap(Pic.Label, Pic.Description,ID3.GetBitmap(Pic.Picuretype))
Next
'Get all standard text information frames:
For i = 0 To ID3.Frames.Size-1
Frame = ID3.Frames.Get(ID3.Frames.GetKeyAt(i))
lv.AddTwoLines(Frame.Name & " - " & Frame.label, Frame.Content)
Next
'Get all comments:
For i = 0 To ID3.Comments.Size-1
Comment = ID3.Comments.Get(ID3.Comments.GetKeyAt(i))
lv.AddTwoLines(Comment.Label & " " & Comment.Language & " " & Comment.Description,Comment.Content)
Next
'Get all other frames:
For i = 0 To ID3.OtherData.Size-1
Other = ID3.otherdata.Get(ID3.otherdata.GetKeyAt(i))
lv.AddTwoLines(Other.Name & " - " & Other.Label, Other.Content)
Next
lv.AddTwoLines("Version", "id3v2." & ID3.Version & "." & ID3.Revision)
Else
ID3.ReadVersion1
lv.AddTwoLines("Title", ID3.V1.Title)
lv.AddTwoLines("Artist", ID3.V1.Artist)
lv.AddTwoLines("Album", ID3.V1.Album)
lv.AddTwoLines("Genre", ID3.V1.Genre)
lv.AddTwoLines("Track", ID3.V1.Track)
lv.AddTwoLines("Comment", ID3.V1.Comment)
lv.AddTwoLines("Version", "id3v1")
End If
If ID3.errCode > 0 Then
lv.AddTwoLines("Error in id3 tag found", "Error " & ID3.ErrCode & " at Position " & ID3.ErrPosition)
End If
End Sub
UPDATE Version 1.1:
Fixed an error with older id3v2 versions (id3v2.2).
Currently this class reads id3v2.3 and id3v1 tags.
id3v2.4 tags are not fully supported.
id3v2.2 tags are not supported.
Attachments
Last edited: