Wish ExoPlayer-ID3 metadata

kisoft

Well-Known Member
Licensed User
Longtime User
Would it be possible to update the Exoplayer for B4A? In the mean while, the original library supports reading MP3 tags, which is interesting for displaying info (like the title of the current song playing) on radio streams.

I can download this data manually from the radio's website using okhttputilis2, but this requires a lot of work and separate treatment of each radio station.
 

kisoft

Well-Known Member
Licensed User
Longtime User
Hi
Thank you for your answer. I found something like this:
https://medium.com/google-exoplayer/exoplayer-2-1-whats-new-2832c09fedab

ID3 metadata and album art
ExoPlayer now parses ID3 metadata from the headers of MP3 and MP4 files. The metadata is placed into the Format object of the corresponding track. If you wish to receive and handle ID3 metadata then add an EventListener to the player via ExoPlayer.addListener. In the listener’s onTracksChanged method, iterate over the tracks looking for metadata. For example:
B4X:
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
  for (int i = 0; i < trackGroups.length; i++) {
    TrackGroup trackGroup = trackGroups.get(i);
    for (int j = 0; j < trackGroup.length; j++) {
      Metadata trackMetadata = trackGroup.getFormat(j).metadata;
      if (trackMetadata != null) {
        // We found metadata. Do something with it here!
      }
    }
  }
}
SimpleExoPlayerView has also been updated to look at ID3 metadata, and will automatically display embedded ID3 album art during audio playbacks. If not desired, this functionality can be disabled using SimpleExoPlayerView’s setUseArtwork method.
 

Pendrush

Well-Known Member
Licensed User
Longtime User
Here is my kotlin code with ExoPlayer v2.11.1
B4X:
player.addMetadataOutput { metadata: Metadata? ->
   hasMetadata = true
   val tmpSongName = extractSongName(metadata.toString())
   LiveDataModel.get().setISongName(tmpSongName)
   notify(tmpSongName)
}
ExoPlayer has method addMetadataOutput.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is very similar to this code: https://www.b4x.com/android/forum/threads/exoplayer-audio-detect.108588/#post-678899

Start with:
B4X:
Sub Player_TrackChanged
   Dim jo As JavaObject = player1
   Dim TrackGroups As JavaObject = jo.GetFieldJO("player").RunMethod("getCurrentTrackGroups", Null)
   For i = 0 To TrackGroups.GetField("length") - 1
       Dim TrackGroup As JavaObject = TrackGroups.RunMethod("get", Array(i))
       For j = 0 To TrackGroup.GetField("length") - 1
           Dim Format As JavaObject = TrackGroup.RunMethodJO("getFormat", Array(j))
           Dim Metadata As JavaObject = Format.GetField("metadata")
           If Metadata.IsInitialized Then
               Log("Found: " & Metadata)
           End If
       Next
   Next
End Sub

MetaData javadocs: https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/metadata/Metadata.html
 

kisoft

Well-Known Member
Licensed User
Longtime User
After a few attempts, I managed to get the name of the station. This is the address of the stream: https://www.rmfon.pl/stacje/ajax_playing_main.txt
B4X:
Sub Player_TrackChanged
    Dim jo As JavaObject = player1
    Dim TrackGroups As JavaObject = jo.GetFieldJO("player").RunMethod("getCurrentTrackGroups", Null)
    For i = 0 To TrackGroups.GetField("length") - 1
        Dim TrackGroup As JavaObject = TrackGroups.RunMethod("get", Array(i))
        For j = 0 To TrackGroup.GetField("length") - 1
            Dim Format As JavaObject = TrackGroup.RunMethodJO("getFormat", Array(j))
            Log(Format)
            Dim Metadata As JavaObject = Format.GetField("metadata")
            If Metadata.IsInitialized Then
            Log("Metadata: " & Metadata) 'will not show you anything
                Dim jo As JavaObject= Metadata.RunMethodJO("get", Array(j))
                Log (jo)
                Dim mime As String = jo.GetField("name")
                Log(mime)
            End If
        Next
    Next
End Sub

B4X:
(Format) Format(null, null, null, audio/mpeg, null, 128000000, null, [-1, -1, -1.0], [2, 44100])
Metadata: (Metadata) com.google.android.exoplayer2.metadata.Metadata@1bf9af3b
(IcyHeaders) IcyHeaders: name="[RMF LADY PANK]", genre="RMF LADY PANK", bitrate=128000000, metadataInterval=1024
[RMF LADY PANK]
 

kisoft

Well-Known Member
Licensed User
Longtime User
Hello
Unfortunately, despite the attempts made, it was not possible to obtain the expected solution. The request remains valid...
 

kisoft

Well-Known Member
Licensed User
Longtime User
That's not accurate. The code from the other thread extracts all the information from the Metadata object.
Yes, but from the useful information is only the name of the stream (radio station). The second approach is off the exoplayer. You can extract a 7.html file from the stream itself and try to download interesting resources. Unfortunately, without synchronization, you can only refresh the download every 5s with a timer.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…