Change Media with TextTracks on ExoPlayer v2.17.0 and v2.17.1
See original GitHub issueHi,
ExoPlayer Version: v2.17.0 and 2.17.1
I am having a single player instance, which I use to pass multiple medias. It helps me to do the change medias. I don’t use ExoPlayer’s Playlist feature. On UI, I show a spinner having multiple test tracks including ‘None’. None will disable the test tracks.
Let’s suppose 1st media is playing back and it has ‘None’ and I disabled the text track’s visibility. In the below code, what i do; i clear the selected indices which basically tells ExoPlayer not to display anything from that text group. Reference https://github.com/google/ExoPlayer/blob/8129675b065bc98330ec775fb7a538c139793070/library/common/src/main/java/com/google/android/exoplayer2/trackselection/TrackSelectionOverrides.java#L123
//actually change track.
TrackGroup trackGroup = mappedTrackInfo.getTrackGroups(rendererIndex).get(groupIndex);
if (!selectedIndices.isEmpty()) {
if (rendererIndex == TRACK_TYPE_TEXT && selectedIndices.get(0) == TRACK_DISABLED) {
// Just clear the selected indices,
// it will let exoplayer know that no tracks from trackGroup should be played
selectedIndices.clear();
}
TrackSelectionOverrides.TrackSelectionOverride trackSelectionOverride = new TrackSelectionOverrides.TrackSelectionOverride(trackGroup, selectedIndices);
TrackSelectionOverrides trackSelectionOverrides = trackSelectionOverridesBuilder
.setOverrideForType(trackSelectionOverride)
.build();
parametersBuilder.setTrackSelectionOverrides(trackSelectionOverrides);
} else {
//clear all the selections if the override is null.
trackSelectionOverridesBuilder.clearOverride(trackGroup);
}
selector.setParameters(parametersBuilder);
Issue: When i change the track (either same media or another one having text tracks), i see that for next track also text tracks are in the disabled state. Ex: Here i tried same content.
‘French’ is the default language having selection flag = 5 . So for the first time, trackSelected
is true
and next time trackSelected
is false
. I think Exo is again retaining some info for the trackgroups.
Screenshots:


PS: Please update te ExoPlayer demo app for changing the tracks; it is still using the deprecated API setSelectionOverride
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (6 by maintainers)
In the demo app for current releases (e.g., 2.17), this is working as intended, because selecting “None” disables the renderer, and disabling the renderer is not tied to any specific
TrackGroups
.I think your problem is probably to do with the way the new style selection overrides apply. Note that a new style override only specifies a single
TrackGroup
:Note also that each of the text tracks is in its own group, because they present different content. So for an override to apply to the second piece of media, it’s only necessary that an equal
TrackGroup
is present to one you’ve set an override for in the first piece of media. This can be true even if the total number of available text tracks is different.You need to make sure that when transitioning to the new piece of media, there aren’t any overrides present that apply to it. For example, create a new and empty
TrackSelectionOverrides.Builder
and make sure to incorporate it into theTrackSelectionParameters
. This may be somewhat related to my earlier point about the line of code that I don’t think is doing anything.Is the text
TrackGroup
in the second piece of media equal to the textTrackGroup
in the first piece of media? If so then it’s working as intended that the override would continue to apply. If you don’t want the override to continue to apply, then you should update the parameters to get rid of it when you switch to playing the second piece of media.Regarding the demo app, we are currently updating both the UI components and demo app to use the new track selection APIs (which, unfortunately, are changing a little again, since we didn’t get everything just how we wanted it the first time).