B4J Question [SOLVED ] Audio File Properties

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All,

Is there a way to get the Audio file properties of an mp3 audio file ? I am mainly looking for the bit rate and the total time. These are in the properties of the file but not in the ID3 tag V1 or V2

1626029633483.png

ID3 v2 area

ID3 v1 area


Thank you in advance
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
#AdditionalJar: mp3agic-0.9.1
Sub Process_Globals
    
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Dim mp3 As JavaObject = LoadMp3File("D:\Documents\Music\222.mp3")
    Log(mp3.RunMethod("getBitrate", Null))
    Log(mp3.RunMethod("getSampleRate", Null))
    Log(mp3.RunMethod("getLengthInMilliseconds", Null))
End Sub

Private Sub LoadMp3File (Path As String) As JavaObject
    Dim jo As JavaObject
    jo.InitializeNewInstance("com.mpatric.mp3agic.Mp3File", Array(Path))
    Return jo
End Sub


Jar: https://repo1.maven.org/maven2/com/mpatric/mp3agic/0.9.1/mp3agic-0.9.1.jar
 
Upvote 0

Peter Lewis

Active Member
Licensed User
Longtime User
B4X:
#AdditionalJar: mp3agic-0.9.1
Sub Process_Globals
   
End Sub

Sub AppStart (Args() As String)
    Log("Hello world!!!")
    Dim mp3 As JavaObject = LoadMp3File("D:\Documents\Music\222.mp3")
    Log(mp3.RunMethod("getBitrate", Null))
    Log(mp3.RunMethod("getSampleRate", Null))
    Log(mp3.RunMethod("getLengthInMilliseconds", Null))
End Sub

Private Sub LoadMp3File (Path As String) As JavaObject
    Dim jo As JavaObject
    jo.InitializeNewInstance("com.mpatric.mp3agic.Mp3File", Array(Path))
    Return jo
End Sub


Jar: https://repo1.maven.org/maven2/com/mpatric/mp3agic/0.9.1/mp3agic-0.9.1.jar
Thank you
 
Upvote 0

CR95

Active Member
Licensed User
By reading the detailed description of the library, I found that it was possible also to get the frames of the MP3 track
Getting ID3v2 frame values
Convenience methods are included to easily get common ID3v2 frames. If you wish to get frame data that does not have convenience methods, or if you wish to access meta-data on frames, direct reading of frames is possible (see further down on this page).

Mp3File mp3file = new Mp3File("SomeMp3File.mp3");
if (mp3file.hasId3v2Tag()) {
ID3v2 id3v2Tag = mp3file.getId3v2Tag();
System.out.println("Track: " + id3v2Tag.getTrack());
I tried something like that :
B4X:
ID2 = mp3.RunMethod("hasId3v2Tag", Null)
If ID2 = True Then
    Dim ListMP3 As Object
    ListMP3 = "getTrack"
    CurTrackTitre = mp3.RunMethod("getId3v2Tag", ListMP3)
    Log ("TitreMP3= " & CurTrackTitre)
EndIf
But I get an error.
Please could you help to get the data from the tag
 
Upvote 0

CR95

Active Member
Licensed User
Final target is to get the parameters from the ID (name, year, album....)
In the sample joined to the library, the author gets them by getting :
- firstly, id3v2Tag = mp3file.getId3v2Tag();
- secondly, the parameter from this tag = id3v2Tag.getTrack());
I tried to reproduce that by calling Erel's subroutine with "getTrack" as parameter.
As I said, it was a try ! I do not know Java world
 
Upvote 0
Top