Skip to content

Commit

Permalink
Remove disabled types in StyledPlayerControlView when selecting tracks.
Browse files Browse the repository at this point in the history
When selecting an explicit track or "Auto", we need to remove any
existing track type disabling. Otherwise the track override won't work.

Issue: google/ExoPlayer#9692
PiperOrigin-RevId: 410250313
  • Loading branch information
tonihei authored and icbaker committed Nov 19, 2021
1 parent e12bfea commit 9d21051
Showing 1 changed file with 18 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.Formatter;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;

/**
Expand Down Expand Up @@ -1936,19 +1938,13 @@ public int getItemCount() {

private static final class TrackInformation {

private TracksInfo tracksInfo;
private int trackGroupIndex;
public final TrackGroupInfo trackGroupInfo;
public final TrackGroup trackGroup;
public final int trackIndex;
public final String trackName;

public TrackInformation(
TracksInfo tracksInfo, int trackGroupIndex, int trackIndex, String trackName) {
this.tracksInfo = tracksInfo;
this.trackGroupIndex = trackGroupIndex;
this.trackGroupInfo = tracksInfo.getTrackGroupInfos().get(trackGroupIndex);
this.trackGroup = trackGroupInfo.getTrackGroup();
this.trackIndex = trackIndex;
this.trackName = trackName;
}
Expand Down Expand Up @@ -2047,11 +2043,15 @@ public void onBindViewHolderAtZeroPosition(SubSettingViewHolder holder) {
.buildUpon()
.clearOverridesOfType(C.TRACK_TYPE_AUDIO)
.build();
Set<@C.TrackType Integer> disabledTrackTypes =
new HashSet<>(trackSelectionParameters.disabledTrackTypes);
disabledTrackTypes.remove(C.TRACK_TYPE_AUDIO);
castNonNull(player)
.setTrackSelectionParameters(
trackSelectionParameters
.buildUpon()
.setTrackSelectionOverrides(trackSelectionOverrides)
.setDisabledTrackTypes(disabledTrackTypes)
.build());
settingsAdapter.setSubTextAtPosition(
SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
Expand All @@ -2061,16 +2061,11 @@ public void onBindViewHolderAtZeroPosition(SubSettingViewHolder holder) {
}

private boolean hasSelectionOverride(TrackSelectionOverrides trackSelectionOverrides) {
int previousTrackGroupIndex = C.INDEX_UNSET;
for (int i = 0; i < tracks.size(); i++) {
TrackInformation track = tracks.get(i);
if (track.trackGroupIndex == previousTrackGroupIndex) {
continue;
}
if (trackSelectionOverrides.getOverride(track.trackGroup) != null) {
TrackGroup trackGroup = tracks.get(i).trackGroupInfo.getTrackGroup();
if (trackSelectionOverrides.getOverride(trackGroup) != null) {
return true;
}
previousTrackGroupIndex = track.trackGroupIndex;
}
return false;
}
Expand All @@ -2083,24 +2078,14 @@ public void onTrackSelection(String subtext) {
@Override
public void init(List<TrackInformation> trackInformations) {
// Update subtext in settings menu with current audio track selection.
boolean hasSelectionOverride = false;
for (int i = 0; i < trackInformations.size(); i++) {
if (checkNotNull(player)
.getTrackSelectionParameters()
.trackSelectionOverrides
.getOverride(trackInformations.get(i).trackGroup)
!= null) {
hasSelectionOverride = true;
break;
}
}
TrackSelectionParameters params = checkNotNull(player).getTrackSelectionParameters();
if (trackInformations.isEmpty()) {
settingsAdapter.setSubTextAtPosition(
SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
getResources().getString(R.string.exo_track_selection_none));
// TODO(insun) : Make the audio item in main settings (settingsAdapater)
// to be non-clickable.
} else if (!hasSelectionOverride) {
} else if (!hasSelectionOverride(params.trackSelectionOverrides)) {
settingsAdapter.setSubTextAtPosition(
SETTINGS_AUDIO_TRACK_SELECTION_POSITION,
getResources().getString(R.string.exo_track_selection_auto));
Expand Down Expand Up @@ -2150,13 +2135,10 @@ public void onBindViewHolder(SubSettingViewHolder holder, int position) {
onBindViewHolderAtZeroPosition(holder);
} else {
TrackInformation track = tracks.get(position - 1);
TrackGroup trackGroup = track.trackGroupInfo.getTrackGroup();
TrackSelectionParameters params = checkNotNull(player).getTrackSelectionParameters();
boolean explicitlySelected =
checkNotNull(player)
.getTrackSelectionParameters()
.trackSelectionOverrides
.getOverride(track.trackGroup)
!= null
&& track.isSelected();
params.trackSelectionOverrides.getOverride(trackGroup) != null && track.isSelected();
holder.textView.setText(track.trackName);
holder.checkView.setVisibility(explicitlySelected ? VISIBLE : INVISIBLE);
holder.itemView.setOnClickListener(
Expand All @@ -2172,13 +2154,17 @@ public void onBindViewHolder(SubSettingViewHolder holder, int position) {
.buildUpon()
.setOverrideForType(
new TrackSelectionOverride(
track.trackGroup, ImmutableList.of(track.trackIndex)))
trackGroup, ImmutableList.of(track.trackIndex)))
.build();
Set<@C.TrackType Integer> disabledTrackTypes =
new HashSet<>(trackSelectionParameters.disabledTrackTypes);
disabledTrackTypes.remove(track.trackGroupInfo.getTrackType());
checkNotNull(player)
.setTrackSelectionParameters(
trackSelectionParameters
.buildUpon()
.setTrackSelectionOverrides(overrides)
.setDisabledTrackTypes(disabledTrackTypes)
.build());
onTrackSelection(track.trackName);
settingsWindow.dismiss();
Expand Down

0 comments on commit 9d21051

Please sign in to comment.