Description
Hey everyone, this is a more conceptual question about exoplayer. I'm trying to understand where I can find the relationship between a media file (e.g. a mp3 file / MediaItem) and the renderer within the code itself.
My use case has me downloading several mp3 files from my server, each with specific file names, and loading them into several renderers, one for each file, for playback. The goal is to be able to access a renderer for a given file--for example: sending a MSG_SET_VOLUME message to a renderer given the filename. I can create the renderers just fine using a custom RenderersFactory, but beyond this I'm having some trouble tracing the relationship between a renderer and the source of its data.
I've looked at TrackSelection and LoadControl, but each have TrackGroups and TrackSelections within their purview, not a direct relationship to a MediaItem. In other words, I don't believe I can tell which file the TrackSelection or TrackGroup is associated with. I've also looked at setting custom metadata for the MediaItems I'm giving my player via setting MediaMetadata on the MediaItem.Builder in the hopes of retrieving it somewhere like LoadControl, but I cannot seem to access the metadata I set, only the ID3 metadata.
For example, here's how I tried to see the metadata I set on a singular MediaItem. I attempted to put the filename as the track title:
//In our activity when we are setting up the player
private String PrepareDebugFiles(){/* ...Ensure our debug files are properly downloaded and present on the device for testing */}
MediaMetadata metadata = new MediaMetadata.Builder().setTitle("MyCustomFileName").build();
MediaItem myFile = new MediaItem.Builder().setMediaMetadata(metadata).setUri(PrepareDebugFiles()).build();
ExoPlayer player = new ExoPlayer.Builder(context)
.setLoadControl(myCustomLoadControl)
.build();
player.setMediaItem(myFile);
player.prepare();
player.play();
//In a custom load control object
public void onTracksSelected(Timeline timeline, MediaSource.MediaPeriodId mediaPeriodId, Renderer[] renderers, TrackGroupArray trackGroups, ExoTrackSelection[] trackSelections){
for(int i = 0; i < trackGroups.length; i++) {
Metadata metadata = trackGroups.get(i).getFormat(0).metadata;
if (metadata != null) {
//Returns some values but not "MyCustomFileName"
Log.d("CustomLoadControl", "Metadata " + metadata.get(0));
}
}
for(int i = 0; i < trackSelections.length; i++){
if (trackSelections[i] != null) {
Metadata metadata = trackSelections[i].getSelectedFormat().metadata;
if (metadata != null) {
//Returns some values but not "MyCustomFileName"
Log.d("CustomLoadControl", "Metadata " + metadata.get(0));
}
}
}
}
Based on the diagram in the glossary, it seems like everything has a one-way relationship when loading from a file and I cannot really walk back up the chain easily.
Any help pointing me in the correct direction would really be appreciated. I'm hoping I missed something obvious.
Thanks.