Commit b2a5298e by olly Committed by Ian Baker

Decouple UI module from ExoPlayer

This change rewrites the UI module's track selection
components to depend on the Player API, allowing us to
finally remove the UI module's dependency on ExoPlayer
as a concrete player implementation.

PiperOrigin-RevId: 432989318
parent 661d7dde
...@@ -29,6 +29,12 @@ ...@@ -29,6 +29,12 @@
`SubtitleConfiguration` field and fall back to the `Factory` value if `SubtitleConfiguration` field and fall back to the `Factory` value if
it's not set it's not set
([#10016](https://github.com/google/ExoPlayer/issues/10016)). ([#10016](https://github.com/google/ExoPlayer/issues/10016)).
* UI:
* Rewrite `TrackSelectionView` and `TrackSelectionDialogBuilder` to work
with the `Player` interface rather than `ExoPlayer`. This allows the
views to be used with other `Player` implementations, and removes the
dependency from the UI module to the ExoPlayer module. This is a
breaking change.
* RTSP: * RTSP:
* Add RTP reader for HEVC * Add RTP reader for HEVC
([#36](https://github.com/androidx/media/pull/36)). ([#36](https://github.com/androidx/media/pull/36)).
......
...@@ -29,6 +29,7 @@ import androidx.fragment.app.FragmentManager; ...@@ -29,6 +29,7 @@ import androidx.fragment.app.FragmentManager;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaItem; import com.google.android.exoplayer2.MediaItem;
import com.google.android.exoplayer2.RenderersFactory; import com.google.android.exoplayer2.RenderersFactory;
import com.google.android.exoplayer2.TracksInfo;
import com.google.android.exoplayer2.drm.DrmInitData; import com.google.android.exoplayer2.drm.DrmInitData;
import com.google.android.exoplayer2.drm.DrmSession; import com.google.android.exoplayer2.drm.DrmSession;
import com.google.android.exoplayer2.drm.DrmSessionEventListener; import com.google.android.exoplayer2.drm.DrmSessionEventListener;
...@@ -43,8 +44,8 @@ import com.google.android.exoplayer2.offline.DownloadRequest; ...@@ -43,8 +44,8 @@ import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.offline.DownloadService; import com.google.android.exoplayer2.offline.DownloadService;
import com.google.android.exoplayer2.source.TrackGroup; import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo; import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo;
import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.android.exoplayer2.upstream.HttpDataSource; import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -69,7 +70,6 @@ public class DownloadTracker { ...@@ -69,7 +70,6 @@ public class DownloadTracker {
private final CopyOnWriteArraySet<Listener> listeners; private final CopyOnWriteArraySet<Listener> listeners;
private final HashMap<Uri, Download> downloads; private final HashMap<Uri, Download> downloads;
private final DownloadIndex downloadIndex; private final DownloadIndex downloadIndex;
private final DefaultTrackSelector.Parameters trackSelectorParameters;
@Nullable private StartDownloadDialogHelper startDownloadDialogHelper; @Nullable private StartDownloadDialogHelper startDownloadDialogHelper;
...@@ -82,7 +82,6 @@ public class DownloadTracker { ...@@ -82,7 +82,6 @@ public class DownloadTracker {
listeners = new CopyOnWriteArraySet<>(); listeners = new CopyOnWriteArraySet<>();
downloads = new HashMap<>(); downloads = new HashMap<>();
downloadIndex = downloadManager.getDownloadIndex(); downloadIndex = downloadManager.getDownloadIndex();
trackSelectorParameters = DownloadHelper.getDefaultTrackSelectorParameters(context);
downloadManager.addListener(new DownloadManagerListener()); downloadManager.addListener(new DownloadManagerListener());
loadDownloads(); loadDownloads();
} }
...@@ -159,7 +158,7 @@ public class DownloadTracker { ...@@ -159,7 +158,7 @@ public class DownloadTracker {
private final class StartDownloadDialogHelper private final class StartDownloadDialogHelper
implements DownloadHelper.Callback, implements DownloadHelper.Callback,
DialogInterface.OnClickListener, TrackSelectionDialog.TrackSelectionListener,
DialogInterface.OnDismissListener { DialogInterface.OnDismissListener {
private final FragmentManager fragmentManager; private final FragmentManager fragmentManager;
...@@ -167,7 +166,6 @@ public class DownloadTracker { ...@@ -167,7 +166,6 @@ public class DownloadTracker {
private final MediaItem mediaItem; private final MediaItem mediaItem;
private TrackSelectionDialog trackSelectionDialog; private TrackSelectionDialog trackSelectionDialog;
private MappedTrackInfo mappedTrackInfo;
private WidevineOfflineLicenseFetchTask widevineOfflineLicenseFetchTask; private WidevineOfflineLicenseFetchTask widevineOfflineLicenseFetchTask;
@Nullable private byte[] keySetId; @Nullable private byte[] keySetId;
...@@ -237,21 +235,13 @@ public class DownloadTracker { ...@@ -237,21 +235,13 @@ public class DownloadTracker {
Log.e(TAG, logMessage, e); Log.e(TAG, logMessage, e);
} }
// DialogInterface.OnClickListener implementation. // TrackSelectionListener implementation.
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onTracksSelected(TrackSelectionParameters trackSelectionParameters) {
for (int periodIndex = 0; periodIndex < downloadHelper.getPeriodCount(); periodIndex++) { for (int periodIndex = 0; periodIndex < downloadHelper.getPeriodCount(); periodIndex++) {
downloadHelper.clearTrackSelections(periodIndex); downloadHelper.clearTrackSelections(periodIndex);
for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) { downloadHelper.addTrackSelection(periodIndex, trackSelectionParameters);
if (!trackSelectionDialog.getIsDisabled(/* rendererIndex= */ i)) {
downloadHelper.addTrackSelectionForSingleRenderer(
periodIndex,
/* rendererIndex= */ i,
trackSelectorParameters,
trackSelectionDialog.getOverrides(/* rendererIndex= */ i));
}
}
} }
DownloadRequest downloadRequest = buildDownloadRequest(); DownloadRequest downloadRequest = buildDownloadRequest();
if (downloadRequest.streamKeys.isEmpty()) { if (downloadRequest.streamKeys.isEmpty()) {
...@@ -316,21 +306,21 @@ public class DownloadTracker { ...@@ -316,21 +306,21 @@ public class DownloadTracker {
return; return;
} }
mappedTrackInfo = downloadHelper.getMappedTrackInfo(/* periodIndex= */ 0); TracksInfo tracksInfo = downloadHelper.getTracksInfo(/* periodIndex= */ 0);
if (!TrackSelectionDialog.willHaveContent(mappedTrackInfo)) { if (!TrackSelectionDialog.willHaveContent(tracksInfo)) {
Log.d(TAG, "No dialog content. Downloading entire stream."); Log.d(TAG, "No dialog content. Downloading entire stream.");
startDownload(); startDownload();
downloadHelper.release(); downloadHelper.release();
return; return;
} }
trackSelectionDialog = trackSelectionDialog =
TrackSelectionDialog.createForMappedTrackInfoAndParameters( TrackSelectionDialog.createForTracksInfoAndParameters(
/* titleId= */ R.string.exo_download_description, /* titleId= */ R.string.exo_download_description,
mappedTrackInfo, tracksInfo,
trackSelectorParameters, DownloadHelper.getDefaultTrackSelectorParameters(context),
/* allowAdaptiveSelections= */ false, /* allowAdaptiveSelections= */ false,
/* allowMultipleOverrides= */ true, /* allowMultipleOverrides= */ true,
/* onClickListener= */ this, /* onTracksSelectedListener= */ this,
/* onDismissListener= */ this); /* onDismissListener= */ this);
trackSelectionDialog.show(fragmentManager, /* tag= */ null); trackSelectionDialog.show(fragmentManager, /* tag= */ null);
} }
......
...@@ -45,7 +45,7 @@ import com.google.android.exoplayer2.offline.DownloadRequest; ...@@ -45,7 +45,7 @@ import com.google.android.exoplayer2.offline.DownloadRequest;
import com.google.android.exoplayer2.source.DefaultMediaSourceFactory; import com.google.android.exoplayer2.source.DefaultMediaSourceFactory;
import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ads.AdsLoader; import com.google.android.exoplayer2.source.ads.AdsLoader;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.android.exoplayer2.ui.StyledPlayerControlView; import com.google.android.exoplayer2.ui.StyledPlayerControlView;
import com.google.android.exoplayer2.ui.StyledPlayerView; import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSource;
...@@ -79,8 +79,7 @@ public class PlayerActivity extends AppCompatActivity ...@@ -79,8 +79,7 @@ public class PlayerActivity extends AppCompatActivity
private Button selectTracksButton; private Button selectTracksButton;
private DataSource.Factory dataSourceFactory; private DataSource.Factory dataSourceFactory;
private List<MediaItem> mediaItems; private List<MediaItem> mediaItems;
private DefaultTrackSelector trackSelector; private TrackSelectionParameters trackSelectionParameters;
private DefaultTrackSelector.Parameters trackSelectionParameters;
private DebugTextViewHelper debugViewHelper; private DebugTextViewHelper debugViewHelper;
private TracksInfo lastSeenTracksInfo; private TracksInfo lastSeenTracksInfo;
private boolean startAutoPlay; private boolean startAutoPlay;
...@@ -113,9 +112,8 @@ public class PlayerActivity extends AppCompatActivity ...@@ -113,9 +112,8 @@ public class PlayerActivity extends AppCompatActivity
playerView.requestFocus(); playerView.requestFocus();
if (savedInstanceState != null) { if (savedInstanceState != null) {
// Restore as DefaultTrackSelector.Parameters in case ExoPlayer specific parameters were set.
trackSelectionParameters = trackSelectionParameters =
DefaultTrackSelector.Parameters.CREATOR.fromBundle( TrackSelectionParameters.CREATOR.fromBundle(
savedInstanceState.getBundle(KEY_TRACK_SELECTION_PARAMETERS)); savedInstanceState.getBundle(KEY_TRACK_SELECTION_PARAMETERS));
startAutoPlay = savedInstanceState.getBoolean(KEY_AUTO_PLAY); startAutoPlay = savedInstanceState.getBoolean(KEY_AUTO_PLAY);
startItemIndex = savedInstanceState.getInt(KEY_ITEM_INDEX); startItemIndex = savedInstanceState.getInt(KEY_ITEM_INDEX);
...@@ -127,8 +125,7 @@ public class PlayerActivity extends AppCompatActivity ...@@ -127,8 +125,7 @@ public class PlayerActivity extends AppCompatActivity
adsLoaderStateBundle); adsLoaderStateBundle);
} }
} else { } else {
trackSelectionParameters = trackSelectionParameters = new TrackSelectionParameters.Builder(/* context= */ this).build();
new DefaultTrackSelector.ParametersBuilder(/* context= */ this).build();
clearStartPosition(); clearStartPosition();
} }
} }
...@@ -237,11 +234,11 @@ public class PlayerActivity extends AppCompatActivity ...@@ -237,11 +234,11 @@ public class PlayerActivity extends AppCompatActivity
public void onClick(View view) { public void onClick(View view) {
if (view == selectTracksButton if (view == selectTracksButton
&& !isShowingTrackSelectionDialog && !isShowingTrackSelectionDialog
&& TrackSelectionDialog.willHaveContent(trackSelector)) { && TrackSelectionDialog.willHaveContent(player)) {
isShowingTrackSelectionDialog = true; isShowingTrackSelectionDialog = true;
TrackSelectionDialog trackSelectionDialog = TrackSelectionDialog trackSelectionDialog =
TrackSelectionDialog.createForTrackSelector( TrackSelectionDialog.createForPlayer(
trackSelector, player,
/* onDismissListener= */ dismissedDialog -> isShowingTrackSelectionDialog = false); /* onDismissListener= */ dismissedDialog -> isShowingTrackSelectionDialog = false);
trackSelectionDialog.show(getSupportFragmentManager(), /* tag= */ null); trackSelectionDialog.show(getSupportFragmentManager(), /* tag= */ null);
} }
...@@ -277,13 +274,11 @@ public class PlayerActivity extends AppCompatActivity ...@@ -277,13 +274,11 @@ public class PlayerActivity extends AppCompatActivity
RenderersFactory renderersFactory = RenderersFactory renderersFactory =
DemoUtil.buildRenderersFactory(/* context= */ this, preferExtensionDecoders); DemoUtil.buildRenderersFactory(/* context= */ this, preferExtensionDecoders);
trackSelector = new DefaultTrackSelector(/* context= */ this);
lastSeenTracksInfo = TracksInfo.EMPTY; lastSeenTracksInfo = TracksInfo.EMPTY;
player = player =
new ExoPlayer.Builder(/* context= */ this) new ExoPlayer.Builder(/* context= */ this)
.setRenderersFactory(renderersFactory) .setRenderersFactory(renderersFactory)
.setMediaSourceFactory(createMediaSourceFactory()) .setMediaSourceFactory(createMediaSourceFactory())
.setTrackSelector(trackSelector)
.build(); .build();
player.setTrackSelectionParameters(trackSelectionParameters); player.setTrackSelectionParameters(trackSelectionParameters);
player.addListener(new PlayerEventListener()); player.addListener(new PlayerEventListener());
...@@ -400,10 +395,7 @@ public class PlayerActivity extends AppCompatActivity ...@@ -400,10 +395,7 @@ public class PlayerActivity extends AppCompatActivity
private void updateTrackSelectorParameters() { private void updateTrackSelectorParameters() {
if (player != null) { if (player != null) {
// Until the demo app is fully migrated to TrackSelectionParameters, rely on ExoPlayer to use trackSelectionParameters = player.getTrackSelectionParameters();
// DefaultTrackSelector by default.
trackSelectionParameters =
(DefaultTrackSelector.Parameters) player.getTrackSelectionParameters();
} }
} }
...@@ -424,8 +416,7 @@ public class PlayerActivity extends AppCompatActivity ...@@ -424,8 +416,7 @@ public class PlayerActivity extends AppCompatActivity
// User controls // User controls
private void updateButtonVisibility() { private void updateButtonVisibility() {
selectTracksButton.setEnabled( selectTracksButton.setEnabled(player != null && TrackSelectionDialog.willHaveContent(player));
player != null && TrackSelectionDialog.willHaveContent(trackSelector));
} }
private void showControls() { private void showControls() {
......
...@@ -16,7 +16,7 @@ apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle" ...@@ -16,7 +16,7 @@ apply from: "$gradle.ext.exoplayerSettingsDir/common_library_config.gradle"
android.buildTypes.debug.testCoverageEnabled true android.buildTypes.debug.testCoverageEnabled true
dependencies { dependencies {
implementation project(modulePrefix + 'library-core') implementation project(modulePrefix + 'library-common')
api 'androidx.media:media:' + androidxMediaVersion api 'androidx.media:media:' + androidxMediaVersion
implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion implementation 'androidx.annotation:annotation:' + androidxAnnotationVersion
implementation 'androidx.recyclerview:recyclerview:' + androidxRecyclerViewVersion implementation 'androidx.recyclerview:recyclerview:' + androidxRecyclerViewVersion
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
*/ */
package com.google.android.exoplayer2.ui; package com.google.android.exoplayer2.ui;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
...@@ -25,16 +23,21 @@ import android.view.LayoutInflater; ...@@ -25,16 +23,21 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StyleRes; import androidx.annotation.StyleRes;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.source.TrackGroupArray; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; import com.google.android.exoplayer2.TracksInfo.TrackGroupInfo;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride; import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo; import com.google.android.exoplayer2.trackselection.TrackSelectionOverride;
import com.google.android.exoplayer2.trackselection.TrackSelectionUtil; import com.google.android.exoplayer2.trackselection.TrackSelectionParameters;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map;
/** Builder for a dialog with a {@link TrackSelectionView}. */ /** Builder for a dialog with a {@link TrackSelectionView}. */
public final class TrackSelectionDialogBuilder { public final class TrackSelectionDialogBuilder {
...@@ -45,25 +48,24 @@ public final class TrackSelectionDialogBuilder { ...@@ -45,25 +48,24 @@ public final class TrackSelectionDialogBuilder {
/** /**
* Called when tracks are selected. * Called when tracks are selected.
* *
* @param isDisabled Whether the renderer is disabled. * @param isDisabled Whether the disabled option is selected.
* @param overrides List of selected track selection overrides for the renderer. * @param overrides The selected track overrides.
*/ */
void onTracksSelected(boolean isDisabled, List<SelectionOverride> overrides); void onTracksSelected(boolean isDisabled, Map<TrackGroup, TrackSelectionOverride> overrides);
} }
private final Context context; private final Context context;
@StyleRes private int themeResId;
private final CharSequence title; private final CharSequence title;
private final MappedTrackInfo mappedTrackInfo; private final List<TrackGroupInfo> trackGroupInfos;
private final int rendererIndex;
private final DialogCallback callback; private final DialogCallback callback;
@StyleRes private int themeResId;
private boolean allowAdaptiveSelections; private boolean allowAdaptiveSelections;
private boolean allowMultipleOverrides; private boolean allowMultipleOverrides;
private boolean showDisableOption; private boolean showDisableOption;
@Nullable private TrackNameProvider trackNameProvider; @Nullable private TrackNameProvider trackNameProvider;
private boolean isDisabled; private boolean isDisabled;
private List<SelectionOverride> overrides; private Map<TrackGroup, TrackSelectionOverride> overrides;
@Nullable private Comparator<Format> trackFormatComparator; @Nullable private Comparator<Format> trackFormatComparator;
/** /**
...@@ -71,59 +73,53 @@ public final class TrackSelectionDialogBuilder { ...@@ -71,59 +73,53 @@ public final class TrackSelectionDialogBuilder {
* *
* @param context The context of the dialog. * @param context The context of the dialog.
* @param title The title of the dialog. * @param title The title of the dialog.
* @param mappedTrackInfo The {@link MappedTrackInfo} containing the track information. * @param trackGroupInfos The {@link TrackGroupInfo TrackGroupInfos} for the track groups.
* @param rendererIndex The renderer index in the {@code mappedTrackInfo} for which the track
* selection is shown.
* @param callback The {@link DialogCallback} invoked when a track selection has been made. * @param callback The {@link DialogCallback} invoked when a track selection has been made.
*/ */
public TrackSelectionDialogBuilder( public TrackSelectionDialogBuilder(
Context context, Context context,
CharSequence title, CharSequence title,
MappedTrackInfo mappedTrackInfo, List<TrackGroupInfo> trackGroupInfos,
int rendererIndex,
DialogCallback callback) { DialogCallback callback) {
this.context = context; this.context = context;
this.title = title; this.title = title;
this.mappedTrackInfo = mappedTrackInfo; this.trackGroupInfos = ImmutableList.copyOf(trackGroupInfos);
this.rendererIndex = rendererIndex;
this.callback = callback; this.callback = callback;
overrides = Collections.emptyList(); overrides = Collections.emptyMap();
} }
/** /**
* Creates a builder for a track selection dialog which automatically updates a {@link * Creates a builder for a track selection dialog.
* DefaultTrackSelector}.
* *
* @param context The context of the dialog. * @param context The context of the dialog.
* @param title The title of the dialog. * @param title The title of the dialog.
* @param trackSelector A {@link DefaultTrackSelector} whose current selection is used to set up * @param player The {@link Player} whose tracks should be selected.
* the dialog and which is updated when new tracks are selected in the dialog. * @param trackType The type of tracks to show for selection.
* @param rendererIndex The renderer index in the {@code trackSelector} for which the track
* selection is shown.
*/ */
public TrackSelectionDialogBuilder( public TrackSelectionDialogBuilder(
Context context, CharSequence title, DefaultTrackSelector trackSelector, int rendererIndex) { Context context, CharSequence title, Player player, @C.TrackType int trackType) {
this.context = context; this.context = context;
this.title = title; this.title = title;
this.mappedTrackInfo = checkNotNull(trackSelector.getCurrentMappedTrackInfo()); List<TrackGroupInfo> allTrackGroupInfos = player.getCurrentTracksInfo().getTrackGroupInfos();
this.rendererIndex = rendererIndex; trackGroupInfos = new ArrayList<>();
for (int i = 0; i < allTrackGroupInfos.size(); i++) {
TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex); TrackGroupInfo trackGroupInfo = allTrackGroupInfos.get(i);
DefaultTrackSelector.Parameters selectionParameters = trackSelector.getParameters(); if (trackGroupInfo.getTrackType() == trackType) {
isDisabled = selectionParameters.getRendererDisabled(rendererIndex); trackGroupInfos.add(trackGroupInfo);
SelectionOverride override = }
selectionParameters.getSelectionOverride(rendererIndex, rendererTrackGroups); }
overrides = override == null ? Collections.emptyList() : Collections.singletonList(override); overrides = Collections.emptyMap();
callback =
this.callback = (isDisabled, overrides) -> {
(newIsDisabled, newOverrides) -> TrackSelectionParameters.Builder parametersBuilder =
trackSelector.setParameters( player.getTrackSelectionParameters().buildUpon();
TrackSelectionUtil.updateParametersWithOverride( parametersBuilder.setTrackTypeDisabled(trackType, isDisabled);
selectionParameters, parametersBuilder.clearOverridesOfType(trackType);
rendererIndex, for (TrackSelectionOverride override : overrides.values()) {
rendererTrackGroups, parametersBuilder.addOverride(override);
newIsDisabled, }
newOverrides.isEmpty() ? null : newOverrides.get(0))); player.setTrackSelectionParameters(parametersBuilder.build());
};
} }
/** /**
...@@ -149,27 +145,28 @@ public final class TrackSelectionDialogBuilder { ...@@ -149,27 +145,28 @@ public final class TrackSelectionDialogBuilder {
} }
/** /**
* Sets the initial selection override to show. * Sets the single initial override.
* *
* @param override The initial override to show, or null for no override. * @param override The initial override, or {@code null} for no override.
* @return This builder, for convenience. * @return This builder, for convenience.
*/ */
public TrackSelectionDialogBuilder setOverride(@Nullable SelectionOverride override) { public TrackSelectionDialogBuilder setOverride(@Nullable TrackSelectionOverride override) {
return setOverrides( return setOverrides(
override == null ? Collections.emptyList() : Collections.singletonList(override)); override == null ? Collections.emptyMap() : ImmutableMap.of(override.trackGroup, override));
} }
/** /**
* Sets the list of initial selection overrides to show. * Sets the initial track overrides. Any overrides that do not correspond to track groups
* * described by {@code trackGroupInfos} that have been given to this instance will be ignored. If
* <p>Note that only the first override will be used unless {@link * {@link #setAllowMultipleOverrides(boolean)} hasn't been set to {@code true} then all but one
* #setAllowMultipleOverrides(boolean)} is set to {@code true}. * override will be ignored. The retained override will be the one whose track group is described
* first in {@code trackGroupInfos}.
* *
* @param overrides The list of initial overrides to show. There must be at most one override for * @param overrides The initially selected track overrides.
* each track group.
* @return This builder, for convenience. * @return This builder, for convenience.
*/ */
public TrackSelectionDialogBuilder setOverrides(List<SelectionOverride> overrides) { public TrackSelectionDialogBuilder setOverrides(
Map<TrackGroup, TrackSelectionOverride> overrides) {
this.overrides = overrides; this.overrides = overrides;
return this; return this;
} }
...@@ -299,12 +296,7 @@ public final class TrackSelectionDialogBuilder { ...@@ -299,12 +296,7 @@ public final class TrackSelectionDialogBuilder {
selectionView.setTrackNameProvider(trackNameProvider); selectionView.setTrackNameProvider(trackNameProvider);
} }
selectionView.init( selectionView.init(
mappedTrackInfo, trackGroupInfos, isDisabled, overrides, trackFormatComparator, /* listener= */ null);
rendererIndex,
isDisabled,
overrides,
trackFormatComparator,
/* listener= */ null);
return (dialog, which) -> return (dialog, which) ->
callback.onTracksSelected(selectionView.getIsDisabled(), selectionView.getOverrides()); callback.onTracksSelected(selectionView.getIsDisabled(), selectionView.getOverrides());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment