Search in sources :

Example 1 with TrackSelectionParameters

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

the class PlayerActivity method initializePlayer.

/**
 * @return Whether initialization was successful.
 */
protected boolean initializePlayer() {
    if (player == null) {
        Intent intent = getIntent();
        mediaItems = createMediaItems(intent);
        if (mediaItems.isEmpty()) {
            return false;
        }
        boolean preferExtensionDecoders = intent.getBooleanExtra(IntentUtil.PREFER_EXTENSION_DECODERS_EXTRA, false);
        RenderersFactory renderersFactory = DemoUtil.buildRenderersFactory(/* context= */
        this, preferExtensionDecoders);
        trackSelector = new DefaultTrackSelector(/* context= */
        this);
        lastSeenTracksInfo = TracksInfo.EMPTY;
        player = new ExoPlayer.Builder(/* context= */
        this).setRenderersFactory(renderersFactory).setMediaSourceFactory(createMediaSourceFactory()).setTrackSelector(trackSelector).build();
        player.setTrackSelectionParameters(trackSelectionParameters);
        player.addListener(new PlayerEventListener());
        player.addAnalyticsListener(new EventLogger(trackSelector));
        player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */
        true);
        player.setPlayWhenReady(startAutoPlay);
        playerView.setPlayer(player);
        serverSideAdsLoader.setPlayer(player);
        debugViewHelper = new DebugTextViewHelper(player, debugTextView);
        debugViewHelper.start();
    }
    boolean haveStartPosition = startItemIndex != C.INDEX_UNSET;
    if (haveStartPosition) {
        player.seekTo(startItemIndex, startPosition);
    }
    player.setMediaItems(mediaItems, /* resetPosition= */
    !haveStartPosition);
    player.prepare();
    updateButtonVisibility();
    return true;
}
Also used : DebugTextViewHelper(com.google.android.exoplayer2.util.DebugTextViewHelper) EventLogger(com.google.android.exoplayer2.util.EventLogger) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) Intent(android.content.Intent) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayer(com.google.android.exoplayer2.ExoPlayer)

Example 2 with TrackSelectionParameters

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

the class TrackSelectionParametersTest method parametersSet_fromDefault_isAsExpected.

@Test
public void parametersSet_fromDefault_isAsExpected() {
    TrackSelectionOverrides trackSelectionOverrides = new TrackSelectionOverrides.Builder().addOverride(new TrackSelectionOverride(new TrackGroup(new Format.Builder().build()))).addOverride(new TrackSelectionOverride(new TrackGroup(new Format.Builder().setId(4).build(), new Format.Builder().setId(5).build()), /* trackIndices= */
    ImmutableList.of(1))).build();
    TrackSelectionParameters parameters = TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT.buildUpon().setMaxVideoSize(/* maxVideoWidth= */
    0, /* maxVideoHeight= */
    1).setMaxVideoFrameRate(2).setMaxVideoBitrate(3).setMinVideoSize(/* minVideoWidth= */
    4, /* minVideoHeight= */
    5).setMinVideoFrameRate(6).setMinVideoBitrate(7).setViewportSize(/* viewportWidth= */
    8, /* viewportHeight= */
    9, /* viewportOrientationMayChange= */
    true).setPreferredVideoMimeTypes(MimeTypes.VIDEO_AV1, MimeTypes.VIDEO_H264).setPreferredAudioLanguages("zh", "jp").setPreferredAudioRoleFlags(C.ROLE_FLAG_COMMENTARY).setMaxAudioChannelCount(10).setMaxAudioBitrate(11).setPreferredAudioMimeTypes(MimeTypes.AUDIO_AC3, MimeTypes.AUDIO_E_AC3).setPreferredTextLanguages("de", "en").setPreferredTextRoleFlags(C.ROLE_FLAG_CAPTION).setSelectUndeterminedTextLanguage(true).setForceLowestBitrate(false).setForceHighestSupportedBitrate(true).setTrackSelectionOverrides(trackSelectionOverrides).setDisabledTrackTypes(ImmutableSet.of(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_TEXT)).build();
    // Video
    assertThat(parameters.maxVideoWidth).isEqualTo(0);
    assertThat(parameters.maxVideoHeight).isEqualTo(1);
    assertThat(parameters.maxVideoFrameRate).isEqualTo(2);
    assertThat(parameters.maxVideoBitrate).isEqualTo(3);
    assertThat(parameters.minVideoWidth).isEqualTo(4);
    assertThat(parameters.minVideoHeight).isEqualTo(5);
    assertThat(parameters.minVideoFrameRate).isEqualTo(6);
    assertThat(parameters.minVideoBitrate).isEqualTo(7);
    assertThat(parameters.viewportWidth).isEqualTo(8);
    assertThat(parameters.viewportHeight).isEqualTo(9);
    assertThat(parameters.viewportOrientationMayChange).isTrue();
    assertThat(parameters.preferredVideoMimeTypes).containsExactly(MimeTypes.VIDEO_AV1, MimeTypes.VIDEO_H264).inOrder();
    // Audio
    assertThat(parameters.preferredAudioLanguages).containsExactly("zh", "jp").inOrder();
    assertThat(parameters.preferredAudioRoleFlags).isEqualTo(C.ROLE_FLAG_COMMENTARY);
    assertThat(parameters.maxAudioChannelCount).isEqualTo(10);
    assertThat(parameters.maxAudioBitrate).isEqualTo(11);
    assertThat(parameters.preferredAudioMimeTypes).containsExactly(MimeTypes.AUDIO_AC3, MimeTypes.AUDIO_E_AC3).inOrder();
    // Text
    assertThat(parameters.preferredTextLanguages).containsExactly("de", "en").inOrder();
    assertThat(parameters.preferredTextRoleFlags).isEqualTo(C.ROLE_FLAG_CAPTION);
    assertThat(parameters.selectUndeterminedTextLanguage).isTrue();
    // General
    assertThat(parameters.forceLowestBitrate).isFalse();
    assertThat(parameters.forceHighestSupportedBitrate).isTrue();
    assertThat(parameters.trackSelectionOverrides).isEqualTo(trackSelectionOverrides);
    assertThat(parameters.disabledTrackTypes).containsExactly(C.TRACK_TYPE_AUDIO, C.TRACK_TYPE_TEXT);
}
Also used : TrackGroup(com.google.android.exoplayer2.source.TrackGroup) TrackSelectionOverride(com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride) Test(org.junit.Test)

Example 3 with TrackSelectionParameters

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

the class DefaultAnalyticsCollector method onTrackSelectionParametersChanged.

@Override
public void onTrackSelectionParametersChanged(TrackSelectionParameters parameters) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, AnalyticsListener.EVENT_TRACK_SELECTION_PARAMETERS_CHANGED, listener -> listener.onTrackSelectionParametersChanged(eventTime, parameters));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Aggregations

Intent (android.content.Intent)1 ExoPlayer (com.google.android.exoplayer2.ExoPlayer)1 RenderersFactory (com.google.android.exoplayer2.RenderersFactory)1 EventTime (com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)1 TrackGroup (com.google.android.exoplayer2.source.TrackGroup)1 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)1 TrackSelectionOverride (com.google.android.exoplayer2.trackselection.TrackSelectionOverrides.TrackSelectionOverride)1 DebugTextViewHelper (com.google.android.exoplayer2.util.DebugTextViewHelper)1 EventLogger (com.google.android.exoplayer2.util.EventLogger)1 Test (org.junit.Test)1