com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride Java Examples

The following examples show how to use com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TrackSelectionUtil.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Updates {@link DefaultTrackSelector.Parameters} with an override.
 *
 * @param parameters The current {@link DefaultTrackSelector.Parameters} to build upon.
 * @param rendererIndex The renderer index to update.
 * @param trackGroupArray The {@link TrackGroupArray} of the renderer.
 * @param isDisabled Whether the renderer should be set disabled.
 * @param override An optional override for the renderer. If null, no override will be set and an
 *     existing override for this renderer will be cleared.
 * @return The updated {@link DefaultTrackSelector.Parameters}.
 */
public static DefaultTrackSelector.Parameters updateParametersWithOverride(
    DefaultTrackSelector.Parameters parameters,
    int rendererIndex,
    TrackGroupArray trackGroupArray,
    boolean isDisabled,
    @Nullable SelectionOverride override) {
  DefaultTrackSelector.ParametersBuilder builder =
      parameters
          .buildUpon()
          .clearSelectionOverrides(rendererIndex)
          .setRendererDisabled(rendererIndex, isDisabled);
  if (override != null) {
    builder.setSelectionOverride(rendererIndex, trackGroupArray, override);
  }
  return builder.build();
}
 
Example #2
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must
 * not be called until after preparation completes.
 *
 * @param periodIndex The period index the track selection is added for.
 * @param rendererIndex The renderer index the track selection is added for.
 * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new
 *     selection of tracks.
 * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code
 *     trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are.
 */
public void addTrackSelectionForSingleRenderer(
    int periodIndex,
    int rendererIndex,
    DefaultTrackSelector.Parameters trackSelectorParameters,
    List<SelectionOverride> overrides) {
  assertPreparedWithMedia();
  DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon();
  for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) {
    builder.setRendererDisabled(/* rendererIndex= */ i, /* disabled= */ i != rendererIndex);
  }
  if (overrides.isEmpty()) {
    addTrackSelection(periodIndex, builder.build());
  } else {
    TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex);
    for (int i = 0; i < overrides.size(); i++) {
      builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i));
      addTrackSelection(periodIndex, builder.build());
    }
  }
}
 
Example #3
Source File: TrackSelectionUtil.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates {@link DefaultTrackSelector.Parameters} with an override.
 *
 * @param parameters The current {@link DefaultTrackSelector.Parameters} to build upon.
 * @param rendererIndex The renderer index to update.
 * @param trackGroupArray The {@link TrackGroupArray} of the renderer.
 * @param isDisabled Whether the renderer should be set disabled.
 * @param override An optional override for the renderer. If null, no override will be set and an
 *     existing override for this renderer will be cleared.
 * @return The updated {@link DefaultTrackSelector.Parameters}.
 */
public static DefaultTrackSelector.Parameters updateParametersWithOverride(
    DefaultTrackSelector.Parameters parameters,
    int rendererIndex,
    TrackGroupArray trackGroupArray,
    boolean isDisabled,
    @Nullable SelectionOverride override) {
  DefaultTrackSelector.ParametersBuilder builder =
      parameters
          .buildUpon()
          .clearSelectionOverrides(rendererIndex)
          .setRendererDisabled(rendererIndex, isDisabled);
  if (override != null) {
    builder.setSelectionOverride(rendererIndex, trackGroupArray, override);
  }
  return builder.build();
}
 
Example #4
Source File: DownloadHelper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must
 * not be called until after preparation completes.
 *
 * @param periodIndex The period index the track selection is added for.
 * @param rendererIndex The renderer index the track selection is added for.
 * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new
 *     selection of tracks.
 * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code
 *     trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are.
 */
public void addTrackSelectionForSingleRenderer(
    int periodIndex,
    int rendererIndex,
    DefaultTrackSelector.Parameters trackSelectorParameters,
    List<SelectionOverride> overrides) {
  assertPreparedWithMedia();
  DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon();
  for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) {
    builder.setRendererDisabled(/* rendererIndex= */ i, /* disabled= */ i != rendererIndex);
  }
  if (overrides.isEmpty()) {
    addTrackSelection(periodIndex, builder.build());
  } else {
    TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex);
    for (int i = 0; i < overrides.size(); i++) {
      builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i));
      addTrackSelection(periodIndex, builder.build());
    }
  }
}
 
Example #5
Source File: TrackSelectionUtil.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates {@link DefaultTrackSelector.Parameters} with an override.
 *
 * @param parameters The current {@link DefaultTrackSelector.Parameters} to build upon.
 * @param rendererIndex The renderer index to update.
 * @param trackGroupArray The {@link TrackGroupArray} of the renderer.
 * @param isDisabled Whether the renderer should be set disabled.
 * @param override An optional override for the renderer. If null, no override will be set and an
 *     existing override for this renderer will be cleared.
 * @return The updated {@link DefaultTrackSelector.Parameters}.
 */
public static DefaultTrackSelector.Parameters updateParametersWithOverride(
    DefaultTrackSelector.Parameters parameters,
    int rendererIndex,
    TrackGroupArray trackGroupArray,
    boolean isDisabled,
    @Nullable SelectionOverride override) {
  DefaultTrackSelector.ParametersBuilder builder =
      parameters
          .buildUpon()
          .clearSelectionOverrides(rendererIndex)
          .setRendererDisabled(rendererIndex, isDisabled);
  if (override != null) {
    builder.setSelectionOverride(rendererIndex, trackGroupArray, override);
  }
  return builder.build();
}
 
Example #6
Source File: DownloadHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must
 * not be called until after preparation completes.
 *
 * @param periodIndex The period index the track selection is added for.
 * @param rendererIndex The renderer index the track selection is added for.
 * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new
 *     selection of tracks.
 * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code
 *     trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are.
 */
public void addTrackSelectionForSingleRenderer(
    int periodIndex,
    int rendererIndex,
    DefaultTrackSelector.Parameters trackSelectorParameters,
    List<SelectionOverride> overrides) {
  assertPreparedWithMedia();
  DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon();
  for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) {
    builder.setRendererDisabled(/* rendererIndex= */ i, /* disabled= */ i != rendererIndex);
  }
  if (overrides.isEmpty()) {
    addTrackSelection(periodIndex, builder.build());
  } else {
    TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex);
    for (int i = 0; i < overrides.size(); i++) {
      builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i));
      addTrackSelection(periodIndex, builder.build());
    }
  }
}
 
Example #7
Source File: TrackSelectionHelper.java    From leafpicrevived with GNU General Public License v3.0 5 votes vote down vote up
private static int[] getTracksRemoving(SelectionOverride override, int removedTrack) {
    int[] tracks = new int[override.length - 1];
    int trackCount = 0;
    for (int i = 0; i < tracks.length + 1; i++) {
        int track = override.tracks[i];
        if (track != removedTrack) {
            tracks[trackCount++] = track;
        }
    }
    return tracks;
}
 
Example #8
Source File: TrackSelectionHelper.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
private void setOverride(int group, int[] tracks, boolean enableRandomAdaptation) {
    TrackSelection.Factory factory = tracks.length == 1 ? FIXED_FACTORY
            : (enableRandomAdaptation ? RANDOM_FACTORY : adaptiveVideoTrackSelectionFactory);
    override = new SelectionOverride(group, tracks);
}
 
Example #9
Source File: TrackSelectionHelper.java    From leafpicrevived with GNU General Public License v3.0 4 votes vote down vote up
private static int[] getTracksAdding(SelectionOverride override, int addedTrack) {
    int[] tracks = override.tracks;
    tracks = Arrays.copyOf(tracks, tracks.length + 1);
    tracks[tracks.length - 1] = addedTrack;
    return tracks;
}