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.
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.
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
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]
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.