Android Question jaudiotagger wrap

noeleon

Active Member
Licensed User
Is anybody creating a wrapper for jaudiotagger? It would be a very invaluable addition to the b4a libs.

If not, maybe somebody share their code for editing ID3 tags. I'd like my app to be able to edit at least the artist, title, and album fields.

Thanks
 

klaus

Expert
Licensed User
Longtime User
I use this code to read the tags:

B4X:
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
 
Upvote 0

noeleon

Active Member
Licensed User
unfortunately ID3v1 is almost useless these days as it's limited to 30 characters. We do have a class that can read id3v2.3 but it can't edit them.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
We do have a class that can read id3v2.3 but it can't edit them.
Why? If it is a B4A Class then you have the Source. If it is a compiled one then it is not a Class but a library.
 
Upvote 0
Top