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
'use below inline java method or use it with JavaObject
Dim jo As JavaObject
jo.InitializeContext
Log(jo.RunMethod("GetMetaData",Array(Metadata)))
End If
Next
Next
End Sub
#if java
import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.metadata.id3.TextInformationFrame;
//for tags, see this: http://id3.org/id3v2.4.0-frames
public String GetMetaData(Metadata trackMetadata){
String album = null;
String title = null;
String artist = null;
for (int k = 0;k < trackMetadata.length();k++){
Metadata.Entry entry = trackMetadata.get(k);
if (entry instanceof TextInformationFrame){
TextInformationFrame textInformationFrame = (TextInformationFrame) entry;
String id = textInformationFrame.id;
if (id != null && id.equals("TALB")){
album = textInformationFrame.value;
} else if (id != null && id.equals(("TIT2"))) {
title = textInformationFrame.value;
} else if (id != null && id.equals(("TPE1"))) {
artist = textInformationFrame.value;
}
}
}
if (album != null && title != null && artist != null){
return album + "-" + title + "-" + artist;
} else {
return "no data";
}
}
#End If