Track Info
Represents information about tracks available in a media player instance.
This class encapsulates a list of tracks, the index of the currently selected track, and the type of tracks represented (video, audio, or text). Each track is stored as a Bundle containing track-specific metadata. For text tracks, the Bundle includes an "id" (the track's index) and a "sourceId" (a string description of the track's source). For video and audio tracks, the Bundle includes only an "id". The class ensures that the track list is never null by providing an empty list as a default when no tracks are available.
Example usage:
TrackInfo trackInfo = player.getTextTrackInfo(); // Could also be video or audio tracks
if (trackInfo != null) {
List<Bundle> tracks = trackInfo.getTracks();
int selectedIndex = trackInfo.getSelectedIndex();
int trackType = trackInfo.getTrackType();
Log.d("Client", "Selected track index: " + selectedIndex);
Log.d("Client", "Number of tracks: " + tracks.size());
String typeString = trackType == SandboxedPlayer.TRACK_TYPE_VIDEO ? "Video" :
trackType == SandboxedPlayer.TRACK_TYPE_AUDIO ? "Audio" : "Text";
Log.d("Client", "Track type: " + typeString);
for (Bundle track : tracks) {
int id = track.getInt("id");
if (trackType == SandboxedPlayer.TRACK_TYPE_TEXT) {
String sourceId = track.getString("sourceId");
Log.d("Client", "Text Track ID: " + id + ", Source: " + sourceId);
} else {
Log.d("Client", "Track ID: " + id);
}
}
}
Content copied to clipboard