Search in sources :

Example 1 with MappedTrackInfo

use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.

the class TrackSelectionDialog method showTabForRenderer.

private static boolean showTabForRenderer(MappedTrackInfo mappedTrackInfo, int rendererIndex) {
    TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(rendererIndex);
    if (trackGroupArray.length == 0) {
        return false;
    }
    int trackType = mappedTrackInfo.getRendererType(rendererIndex);
    return isSupportedTrackType(trackType);
}
Also used : TrackGroupArray(androidx.media3.common.TrackGroupArray)

Example 2 with MappedTrackInfo

use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.

the class TrackSelectionDialog method init.

private void init(int titleId, MappedTrackInfo mappedTrackInfo, DefaultTrackSelector.Parameters initialParameters, boolean allowAdaptiveSelections, boolean allowMultipleOverrides, DialogInterface.OnClickListener onClickListener, DialogInterface.OnDismissListener onDismissListener) {
    this.titleId = titleId;
    this.onClickListener = onClickListener;
    this.onDismissListener = onDismissListener;
    for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
        if (showTabForRenderer(mappedTrackInfo, i)) {
            int trackType = mappedTrackInfo.getRendererType(/* rendererIndex= */
            i);
            TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(i);
            TrackSelectionViewFragment tabFragment = new TrackSelectionViewFragment();
            tabFragment.init(mappedTrackInfo, /* rendererIndex= */
            i, initialParameters.getRendererDisabled(/* rendererIndex= */
            i), initialParameters.getSelectionOverride(/* rendererIndex= */
            i, trackGroupArray), allowAdaptiveSelections, allowMultipleOverrides);
            tabFragments.put(i, tabFragment);
            tabTrackTypes.add(trackType);
        }
    }
}
Also used : TrackGroupArray(androidx.media3.common.TrackGroupArray)

Example 3 with MappedTrackInfo

use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.

the class TrackSelectionDialog method createForTrackSelector.

/**
 * Creates a dialog for a given {@link DefaultTrackSelector}, whose parameters will be
 * automatically updated when tracks are selected.
 *
 * @param trackSelector The {@link DefaultTrackSelector}.
 * @param onDismissListener A {@link DialogInterface.OnDismissListener} to call when the dialog is
 *     dismissed.
 */
public static TrackSelectionDialog createForTrackSelector(DefaultTrackSelector trackSelector, DialogInterface.OnDismissListener onDismissListener) {
    MappedTrackInfo mappedTrackInfo = Assertions.checkNotNull(trackSelector.getCurrentMappedTrackInfo());
    TrackSelectionDialog trackSelectionDialog = new TrackSelectionDialog();
    DefaultTrackSelector.Parameters parameters = trackSelector.getParameters();
    trackSelectionDialog.init(/* titleId= */
    R.string.track_selection_title, mappedTrackInfo, /* initialParameters = */
    parameters, /* allowAdaptiveSelections= */
    true, /* allowMultipleOverrides= */
    false, /* onClickListener= */
    (dialog, which) -> {
        DefaultTrackSelector.ParametersBuilder builder = parameters.buildUpon();
        for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
            builder.clearSelectionOverrides(/* rendererIndex= */
            i).setRendererDisabled(/* rendererIndex= */
            i, trackSelectionDialog.getIsDisabled(/* rendererIndex= */
            i));
            List<SelectionOverride> overrides = trackSelectionDialog.getOverrides(/* rendererIndex= */
            i);
            if (!overrides.isEmpty()) {
                builder.setSelectionOverride(/* rendererIndex= */
                i, mappedTrackInfo.getTrackGroups(/* rendererIndex= */
                i), overrides.get(0));
            }
        }
        trackSelector.setParameters(builder);
    }, onDismissListener);
    return trackSelectionDialog;
}
Also used : SelectionOverride(androidx.media3.exoplayer.trackselection.DefaultTrackSelector.SelectionOverride) DefaultTrackSelector(androidx.media3.exoplayer.trackselection.DefaultTrackSelector) MappedTrackInfo(androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo)

Example 4 with MappedTrackInfo

use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.

the class DownloadHelper method onMediaPrepared.

// Initialization of array of Lists.
@SuppressWarnings("unchecked")
private void onMediaPrepared() {
    checkNotNull(mediaPreparer);
    checkNotNull(mediaPreparer.mediaPeriods);
    checkNotNull(mediaPreparer.timeline);
    int periodCount = mediaPreparer.mediaPeriods.length;
    int rendererCount = rendererCapabilities.length;
    trackSelectionsByPeriodAndRenderer = (List<ExoTrackSelection>[][]) new List<?>[periodCount][rendererCount];
    immutableTrackSelectionsByPeriodAndRenderer = (List<ExoTrackSelection>[][]) new List<?>[periodCount][rendererCount];
    for (int i = 0; i < periodCount; i++) {
        for (int j = 0; j < rendererCount; j++) {
            trackSelectionsByPeriodAndRenderer[i][j] = new ArrayList<>();
            immutableTrackSelectionsByPeriodAndRenderer[i][j] = Collections.unmodifiableList(trackSelectionsByPeriodAndRenderer[i][j]);
        }
    }
    trackGroupArrays = new TrackGroupArray[periodCount];
    mappedTrackInfos = new MappedTrackInfo[periodCount];
    for (int i = 0; i < periodCount; i++) {
        trackGroupArrays[i] = mediaPreparer.mediaPeriods[i].getTrackGroups();
        TrackSelectorResult trackSelectorResult = runTrackSelection(/* periodIndex= */
        i);
        trackSelector.onSelectionActivated(trackSelectorResult.info);
        mappedTrackInfos[i] = checkNotNull(trackSelector.getCurrentMappedTrackInfo());
    }
    setPreparedWithMedia();
    checkNotNull(callbackHandler).post(() -> checkNotNull(callback).onPrepared(this));
}
Also used : TrackSelectorResult(androidx.media3.exoplayer.trackselection.TrackSelectorResult) ExoTrackSelection(androidx.media3.exoplayer.trackselection.ExoTrackSelection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with MappedTrackInfo

use of androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo in project media by androidx.

the class DefaultTrackSelector method maybeConfigureRenderersForTunneling.

// Utility methods.
/**
 * Determines whether tunneling can be enabled, replacing {@link RendererConfiguration}s in {@code
 * rendererConfigurations} with configurations that enable tunneling on the appropriate renderers
 * if so.
 *
 * @param mappedTrackInfo Mapped track information.
 * @param renderererFormatSupports The {@link Capabilities} for each mapped track, indexed by
 *     renderer, track group and track (in that order).
 * @param rendererConfigurations The renderer configurations. Configurations may be replaced with
 *     ones that enable tunneling as a result of this call.
 * @param trackSelections The renderer track selections.
 */
private static void maybeConfigureRenderersForTunneling(MappedTrackInfo mappedTrackInfo, @Capabilities int[][][] renderererFormatSupports, @NullableType RendererConfiguration[] rendererConfigurations, @NullableType ExoTrackSelection[] trackSelections) {
    // Check whether we can enable tunneling. To enable tunneling we require exactly one audio and
    // one video renderer to support tunneling and have a selection.
    int tunnelingAudioRendererIndex = -1;
    int tunnelingVideoRendererIndex = -1;
    boolean enableTunneling = true;
    for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
        int rendererType = mappedTrackInfo.getRendererType(i);
        ExoTrackSelection trackSelection = trackSelections[i];
        if ((rendererType == C.TRACK_TYPE_AUDIO || rendererType == C.TRACK_TYPE_VIDEO) && trackSelection != null) {
            if (rendererSupportsTunneling(renderererFormatSupports[i], mappedTrackInfo.getTrackGroups(i), trackSelection)) {
                if (rendererType == C.TRACK_TYPE_AUDIO) {
                    if (tunnelingAudioRendererIndex != -1) {
                        enableTunneling = false;
                        break;
                    } else {
                        tunnelingAudioRendererIndex = i;
                    }
                } else {
                    if (tunnelingVideoRendererIndex != -1) {
                        enableTunneling = false;
                        break;
                    } else {
                        tunnelingVideoRendererIndex = i;
                    }
                }
            }
        }
    }
    enableTunneling &= tunnelingAudioRendererIndex != -1 && tunnelingVideoRendererIndex != -1;
    if (enableTunneling) {
        RendererConfiguration tunnelingRendererConfiguration = new RendererConfiguration(/* tunneling= */
        true);
        rendererConfigurations[tunnelingAudioRendererIndex] = tunnelingRendererConfiguration;
        rendererConfigurations[tunnelingVideoRendererIndex] = tunnelingRendererConfiguration;
    }
}
Also used : RendererConfiguration(androidx.media3.exoplayer.RendererConfiguration) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Aggregations

TrackGroupArray (androidx.media3.common.TrackGroupArray)11 TrackGroup (androidx.media3.common.TrackGroup)8 MappedTrackInfo (androidx.media3.exoplayer.trackselection.MappingTrackSelector.MappedTrackInfo)8 SuppressLint (android.annotation.SuppressLint)5 Point (android.graphics.Point)5 Nullable (androidx.annotation.Nullable)5 RendererCapabilities (androidx.media3.exoplayer.RendererCapabilities)5 Capabilities (androidx.media3.exoplayer.RendererCapabilities.Capabilities)4 DefaultTrackSelector (androidx.media3.exoplayer.trackselection.DefaultTrackSelector)4 CheckedTextView (android.widget.CheckedTextView)3 TrackSelection (androidx.media3.common.TrackSelection)3 TracksInfo (androidx.media3.common.TracksInfo)3 SelectionOverride (androidx.media3.exoplayer.trackselection.DefaultTrackSelector.SelectionOverride)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Pair (android.util.Pair)2 SparseArray (android.util.SparseArray)2 Format (androidx.media3.common.Format)2 TrackSelectionOverride (androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride)2 RendererConfiguration (androidx.media3.exoplayer.RendererConfiguration)2