Search in sources :

Example 11 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

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(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Example 12 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class MainActivity method initializePlayer.

private void initializePlayer() {
    Intent intent = getIntent();
    String action = intent.getAction();
    Uri uri = ACTION_VIEW.equals(action) ? Assertions.checkNotNull(intent.getData()) : Uri.parse(DEFAULT_MEDIA_URI);
    DrmSessionManager drmSessionManager;
    if (Util.SDK_INT >= 18 && intent.hasExtra(DRM_SCHEME_EXTRA)) {
        String drmScheme = Assertions.checkNotNull(intent.getStringExtra(DRM_SCHEME_EXTRA));
        String drmLicenseUrl = Assertions.checkNotNull(intent.getStringExtra(DRM_LICENSE_URL_EXTRA));
        UUID drmSchemeUuid = Assertions.checkNotNull(Util.getDrmUuid(drmScheme));
        HttpDataSource.Factory licenseDataSourceFactory = new DefaultHttpDataSource.Factory();
        HttpMediaDrmCallback drmCallback = new HttpMediaDrmCallback(drmLicenseUrl, licenseDataSourceFactory);
        drmSessionManager = new DefaultDrmSessionManager.Builder().setUuidAndExoMediaDrmProvider(drmSchemeUuid, FrameworkMediaDrm.DEFAULT_PROVIDER).build(drmCallback);
    } else {
        drmSessionManager = DrmSessionManager.DRM_UNSUPPORTED;
    }
    DataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(this);
    MediaSource mediaSource;
    @C.ContentType int type = Util.inferContentType(uri, intent.getStringExtra(EXTENSION_EXTRA));
    if (type == C.TYPE_DASH) {
        mediaSource = new DashMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else if (type == C.TYPE_OTHER) {
        mediaSource = new ProgressiveMediaSource.Factory(dataSourceFactory).setDrmSessionManagerProvider(unusedMediaItem -> drmSessionManager).createMediaSource(MediaItem.fromUri(uri));
    } else {
        throw new IllegalStateException();
    }
    ExoPlayer player = new ExoPlayer.Builder(getApplicationContext()).build();
    player.setRepeatMode(Player.REPEAT_MODE_ALL);
    player.setMediaSource(mediaSource);
    player.prepare();
    player.play();
    VideoProcessingGLSurfaceView videoProcessingGLSurfaceView = Assertions.checkNotNull(this.videoProcessingGLSurfaceView);
    videoProcessingGLSurfaceView.setPlayer(player);
    Assertions.checkNotNull(playerView).setPlayer(player);
    player.addAnalyticsListener(new EventLogger(/* trackSelector= */
    null));
    this.player = player;
}
Also used : Context(android.content.Context) Util(com.google.android.exoplayer2.util.Util) Bundle(android.os.Bundle) FrameworkMediaDrm(com.google.android.exoplayer2.drm.FrameworkMediaDrm) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) Intent(android.content.Intent) Player(com.google.android.exoplayer2.Player) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) Toast(android.widget.Toast) EventLogger(com.google.android.exoplayer2.util.EventLogger) MediaSource(com.google.android.exoplayer2.source.MediaSource) C(com.google.android.exoplayer2.C) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) MediaItem(com.google.android.exoplayer2.MediaItem) HttpMediaDrmCallback(com.google.android.exoplayer2.drm.HttpMediaDrmCallback) StyledPlayerView(com.google.android.exoplayer2.ui.StyledPlayerView) UUID(java.util.UUID) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) GlUtil(com.google.android.exoplayer2.util.GlUtil) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) Nullable(androidx.annotation.Nullable) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) Activity(android.app.Activity) Assertions(com.google.android.exoplayer2.util.Assertions) EventLogger(com.google.android.exoplayer2.util.EventLogger) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) DrmSessionManager(com.google.android.exoplayer2.drm.DrmSessionManager) DefaultDrmSessionManager(com.google.android.exoplayer2.drm.DefaultDrmSessionManager) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) Intent(android.content.Intent) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) Uri(android.net.Uri) DefaultDataSource(com.google.android.exoplayer2.upstream.DefaultDataSource) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DataSource(com.google.android.exoplayer2.upstream.DataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) ProgressiveMediaSource(com.google.android.exoplayer2.source.ProgressiveMediaSource) DashMediaSource(com.google.android.exoplayer2.source.dash.DashMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) HttpDataSource(com.google.android.exoplayer2.upstream.HttpDataSource) DefaultHttpDataSource(com.google.android.exoplayer2.upstream.DefaultHttpDataSource) HttpMediaDrmCallback(com.google.android.exoplayer2.drm.HttpMediaDrmCallback) UUID(java.util.UUID)

Example 13 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class ExoPlayerTest method allActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreReused.

@Test
public void allActivatedTrackSelectionAreReleasedWhenTrackSelectionsAreReused() throws Exception {
    MediaSource mediaSource = new FakeMediaSource(new FakeTimeline(), ExoPlayerTestRunner.VIDEO_FORMAT, ExoPlayerTestRunner.AUDIO_FORMAT);
    FakeRenderer videoRenderer = new FakeRenderer(C.TRACK_TYPE_VIDEO);
    FakeRenderer audioRenderer = new FakeRenderer(C.TRACK_TYPE_AUDIO);
    final FakeTrackSelector trackSelector = new FakeTrackSelector(/* mayReuseTrackSelection= */
    true);
    ActionSchedule disableTrackAction = new ActionSchedule.Builder(TAG).pause().waitForPlaybackState(Player.STATE_READY).disableRenderer(0).play().build();
    new ExoPlayerTestRunner.Builder(context).setMediaSources(mediaSource).setRenderers(videoRenderer, audioRenderer).setTrackSelector(trackSelector).setActionSchedule(disableTrackAction).build().start().blockUntilEnded(TIMEOUT_MS);
    List<FakeTrackSelection> createdTrackSelections = trackSelector.getAllTrackSelections();
    int numSelectionsEnabled = 0;
    // Assert that all tracks selection are disabled at the end of the playback.
    for (FakeTrackSelection trackSelection : createdTrackSelections) {
        assertThat(trackSelection.isEnabled).isFalse();
        numSelectionsEnabled += trackSelection.enableCount;
    }
    // There are 2 renderers, and track selections are made twice. The second time one renderer is
    // disabled, and the selector re-uses the previous selection for the enabled renderer. So we
    // expect two track selections, one of which will have been enabled twice.
    assertThat(createdTrackSelections).hasSize(2);
    assertThat(numSelectionsEnabled).isEqualTo(3);
}
Also used : FakeRenderer(com.google.android.exoplayer2.testutil.FakeRenderer) FakeTrackSelection(com.google.android.exoplayer2.testutil.FakeTrackSelection) ServerSideAdInsertionMediaSource(com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource) FakeAdaptiveMediaSource(com.google.android.exoplayer2.testutil.FakeAdaptiveMediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) ConcatenatingMediaSource(com.google.android.exoplayer2.source.ConcatenatingMediaSource) MediaSource(com.google.android.exoplayer2.source.MediaSource) CompositeMediaSource(com.google.android.exoplayer2.source.CompositeMediaSource) ClippingMediaSource(com.google.android.exoplayer2.source.ClippingMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeMediaSource(com.google.android.exoplayer2.testutil.FakeMediaSource) FakeTrackSelector(com.google.android.exoplayer2.testutil.FakeTrackSelector) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) FakeTimeline(com.google.android.exoplayer2.testutil.FakeTimeline) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Example 14 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class EventLogger method onTracksChanged.

@Override
public void onTracksChanged(EventTime eventTime, TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    MappedTrackInfo mappedTrackInfo = trackSelector != null ? trackSelector.getCurrentMappedTrackInfo() : null;
    if (mappedTrackInfo == null) {
        logd(eventTime, "tracks", "[]");
        return;
    }
    logd("tracks [" + getEventTimeString(eventTime));
    // Log tracks associated to renderers.
    int rendererCount = mappedTrackInfo.getRendererCount();
    for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
        TrackGroupArray rendererTrackGroups = mappedTrackInfo.getTrackGroups(rendererIndex);
        TrackSelection trackSelection = trackSelections.get(rendererIndex);
        if (rendererTrackGroups.length == 0) {
            logd("  " + mappedTrackInfo.getRendererName(rendererIndex) + " []");
        } else {
            logd("  " + mappedTrackInfo.getRendererName(rendererIndex) + " [");
            for (int groupIndex = 0; groupIndex < rendererTrackGroups.length; groupIndex++) {
                TrackGroup trackGroup = rendererTrackGroups.get(groupIndex);
                String adaptiveSupport = getAdaptiveSupportString(trackGroup.length, mappedTrackInfo.getAdaptiveSupport(rendererIndex, groupIndex, /* includeCapabilitiesExceededTracks= */
                false));
                logd("    Group:" + trackGroup.id + ", adaptive_supported=" + adaptiveSupport + " [");
                for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
                    String status = getTrackStatusString(trackSelection, trackGroup, trackIndex);
                    @Capabilities int capabilities = mappedTrackInfo.getCapabilities(rendererIndex, groupIndex, trackIndex);
                    String formatSupport = getFormatSupportString(getFormatSupport(capabilities));
                    String hardwareAccelerationSupport = getHardwareAccelerationSupport(capabilities) == HARDWARE_ACCELERATION_SUPPORTED ? ", accelerated=YES" : "";
                    String decoderSupport = getDecoderSupport(capabilities) == DECODER_SUPPORT_FALLBACK ? ", fallback=YES" : "";
                    logd("      " + status + " Track:" + trackIndex + ", " + Format.toLogString(trackGroup.getFormat(trackIndex)) + ", supported=" + formatSupport + hardwareAccelerationSupport + decoderSupport);
                }
                logd("    ]");
            }
            // Log metadata for at most one of the tracks selected for the renderer.
            if (trackSelection != null) {
                for (int selectionIndex = 0; selectionIndex < trackSelection.length(); selectionIndex++) {
                    Metadata metadata = trackSelection.getFormat(selectionIndex).metadata;
                    if (metadata != null) {
                        logd("    Metadata [");
                        printMetadata(metadata, "      ");
                        logd("    ]");
                        break;
                    }
                }
            }
            logd("  ]");
        }
    }
    // Log tracks not associated with a renderer.
    TrackGroupArray unassociatedTrackGroups = mappedTrackInfo.getUnmappedTrackGroups();
    if (unassociatedTrackGroups.length > 0) {
        logd("  Unmapped [");
        for (int groupIndex = 0; groupIndex < unassociatedTrackGroups.length; groupIndex++) {
            logd("    Group:" + groupIndex + " [");
            TrackGroup trackGroup = unassociatedTrackGroups.get(groupIndex);
            for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
                String status = getTrackStatusString(false);
                String formatSupport = getFormatSupportString(C.FORMAT_UNSUPPORTED_TYPE);
                logd("      " + status + " Track:" + trackIndex + ", " + Format.toLogString(trackGroup.getFormat(trackIndex)) + ", supported=" + formatSupport);
            }
            logd("    ]");
        }
        logd("  ]");
    }
    logd("]");
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Capabilities(com.google.android.exoplayer2.RendererCapabilities.Capabilities) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) Metadata(com.google.android.exoplayer2.metadata.Metadata) Util.getFormatSupportString(com.google.android.exoplayer2.util.Util.getFormatSupportString) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo) TrackSelection(com.google.android.exoplayer2.trackselection.TrackSelection)

Example 15 with TrackSelector

use of com.google.android.exoplayer2.trackselection.TrackSelector in project ExoPlayer by google.

the class MappingTrackSelectorTest method selectTracks_audioAndVideo_sameOrderAsRenderers_mappedToCorrectRenderer.

@Test
public void selectTracks_audioAndVideo_sameOrderAsRenderers_mappedToCorrectRenderer() throws ExoPlaybackException {
    FakeMappingTrackSelector trackSelector = new FakeMappingTrackSelector();
    RendererCapabilities[] rendererCapabilities = new RendererCapabilities[] { VIDEO_CAPABILITIES, AUDIO_CAPABILITIES };
    TrackGroupArray trackGroups = new TrackGroupArray(VIDEO_TRACK_GROUP, AUDIO_TRACK_GROUP);
    trackSelector.selectTracks(rendererCapabilities, trackGroups, periodId, TIMELINE);
    trackSelector.assertMappedTrackGroups(/* rendererIndex= */
    0, VIDEO_TRACK_GROUP);
    trackSelector.assertMappedTrackGroups(/* rendererIndex= */
    1, AUDIO_TRACK_GROUP);
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Aggregations

DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)16 DefaultLoadControl (com.google.android.exoplayer2.DefaultLoadControl)11 Test (org.junit.Test)10 MediaSource (com.google.android.exoplayer2.source.MediaSource)8 ExoPlayerFactory (com.google.android.exoplayer2.ExoPlayerFactory)7 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)7 AdaptiveTrackSelection (com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection)7 TrackSelection (com.google.android.exoplayer2.trackselection.TrackSelection)7 DefaultRenderersFactory (com.google.android.exoplayer2.DefaultRenderersFactory)6 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)6 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)5 ConcatenatingMediaSource (com.google.android.exoplayer2.source.ConcatenatingMediaSource)5 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)5 TrackSelector (com.google.android.exoplayer2.trackselection.TrackSelector)5 LoadControl (com.google.android.exoplayer2.LoadControl)4 SimpleExoPlayer (com.google.android.exoplayer2.SimpleExoPlayer)4 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)4 CompositeMediaSource (com.google.android.exoplayer2.source.CompositeMediaSource)4 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)4 ServerSideAdInsertionMediaSource (com.google.android.exoplayer2.source.ads.ServerSideAdInsertionMediaSource)4