I have an android application which streams videos with ExoPlayer. I want to add language support to the streams. What languages the stream will have, must be taken from the stream's metadata.
In ExoPlayer library I found the way to get list of the tracks from the stream by following:
player.getCurrentTrackGroups().get(i).getFormat(i) //player is SimpleExoPlayer class
but this give me kind of raw information, here is videos, audios, and other tracks that need to be labeled. printed formats looks like following:
Format(1/100, null, video/avc, -1, null, [1920, 1080, -1.0], [-1, -1])
Format(1/8292, null, application/cea-608, -1, null, [-1, -1, -1.0], [-1, -1])
Format(1/200, null, audio/mpeg-L2, -1, , [-1, -1, -1.0], [2, 48000])
Format(1/201, null, audio/mpeg-L2, -1, , [-1, -1, -1.0], [2, 48000])
I wonder if there is an easier way to get only audio tracks and their required information for switching between them for later.
My next problem is I don't know how to switch between the audio tracks. I searched and there is an answer accepted that this is done by the following code:
player.selectTrack(FullPlayer.TYPE_AUDIO, ExoPlayer.TRACK_DEFAULT);
this code is taken from this answer.
Problem is, that my SimpleExoPlayer class has not this function. I have exoplayer 2.8.2 and neither SimpleExoPlayer nor ExoPlayer class got that function. So i'm stuck there.
Another found answer was from DefaultTrackSelector class which has following face:
trackSelector.setParameters( trackSelector.getParameters().buildUpon().setPreferredAudioLanguage("eng"));
this looks like simple and good way, But not all streams are labeled like that. many tracks has no string for language name. Only thing that they have different is ID string. And passing the id string does not work.