Java Code Examples for com.google.android.exoplayer2.trackselection.DefaultTrackSelector#SelectionOverride

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: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
public int getSelectedTrackIndex(@NonNull RendererType type, int groupIndex) {
    // Retrieves the available tracks
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
    ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, groupIndex, mappedTrackInfo);
    TrackGroupArray trackGroupArray = tracksInfo.rendererTrackIndex == C.INDEX_UNSET ?
            null : mappedTrackInfo.getTrackGroups(tracksInfo.rendererTrackIndex);
    if (trackGroupArray == null || trackGroupArray.length == 0) {
        return -1;
    }

    // Verifies the track selection has been overridden
    DefaultTrackSelector.SelectionOverride selectionOverride = trackSelector.getParameters().getSelectionOverride(tracksInfo.rendererTrackIndex, trackGroupArray);
    if (selectionOverride == null || selectionOverride.groupIndex != tracksInfo.rendererTrackGroupIndex || selectionOverride.length <= 0) {
        return -1;
    }

    return selectionOverride.tracks[0]; // In the current implementation only one track can be selected at a time so get the first one.
}
 
Example 2
Source File: ExoMediaPlayer.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
public void setRendererEnabled(@NonNull RendererType type, boolean enabled) {
    MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo();
    ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, 0, mappedTrackInfo);
    if (!tracksInfo.rendererTrackIndexes.isEmpty()) {
        boolean enabledSomething = false;
        DefaultTrackSelector.ParametersBuilder parametersBuilder = trackSelector.buildUponParameters();
        for (int rendererTrackIndex : tracksInfo.rendererTrackIndexes) {
            if (enabled) {
                DefaultTrackSelector.SelectionOverride selectionOverride = trackSelector.getParameters().getSelectionOverride(rendererTrackIndex, mappedTrackInfo.getTrackGroups(rendererTrackIndex));
                // check whether the renderer has been selected before
                // other renderers should be kept disabled to avoid playback errors
                if (selectionOverride != null) {
                    parametersBuilder.setRendererDisabled(rendererTrackIndex, false);
                    enabledSomething = true;
                }
            } else {
                parametersBuilder.setRendererDisabled(rendererTrackIndex, true);
            }
        }
        if (enabled && !enabledSomething) {
            // if nothing has been enabled enable the first sequential renderer
            parametersBuilder.setRendererDisabled(tracksInfo.rendererTrackIndexes.get(0), false);
        }
        trackSelector.setParameters(parametersBuilder);
    }
}
 
Example 3
Source File: ExoPlayerAudioTrackSelector.java    From no-player with Apache License 2.0 5 votes vote down vote up
public boolean selectAudioTrack(PlayerAudioTrack audioTrack, RendererTypeRequester rendererTypeRequester) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(AUDIO, rendererTypeRequester);

    DefaultTrackSelector.SelectionOverride selectionOverride = new DefaultTrackSelector.SelectionOverride(
            audioTrack.groupIndex(),
            audioTrack.formatIndex()
    );
    return trackSelector.setSelectionOverride(AUDIO, rendererTypeRequester, trackGroups, selectionOverride);
}
 
Example 4
Source File: ExoPlayerTrackSelector.java    From no-player with Apache License 2.0 5 votes vote down vote up
boolean setSelectionOverride(TrackType trackType,
                             RendererTypeRequester rendererTypeRequester,
                             TrackGroupArray trackGroups,
                             DefaultTrackSelector.SelectionOverride selectionOverride) {
    Optional<Integer> rendererIndex = rendererTrackIndexExtractor.extract(trackType, mappedTrackInfoLength(), rendererTypeRequester);
    if (rendererIndex.isPresent()) {
        trackSelector.setParameters(trackSelector
                .buildUponParameters()
                .setSelectionOverride(rendererIndex.get(), trackGroups, selectionOverride)
        );
        return true;
    } else {
        return false;
    }
}
 
Example 5
Source File: ExoPlayerVideoTrackSelector.java    From no-player with Apache License 2.0 5 votes vote down vote up
public boolean selectVideoTrack(PlayerVideoTrack videoTrack, RendererTypeRequester rendererTypeRequester) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(VIDEO, rendererTypeRequester);

    DefaultTrackSelector.SelectionOverride selectionOverride = new DefaultTrackSelector.SelectionOverride(
            videoTrack.groupIndex(),
            videoTrack.formatIndex()
    );
    return trackSelector.setSelectionOverride(VIDEO, rendererTypeRequester, trackGroups, selectionOverride);
}
 
Example 6
Source File: ExoPlayerSubtitleTrackSelector.java    From no-player with Apache License 2.0 5 votes vote down vote up
public boolean selectTextTrack(PlayerSubtitleTrack subtitleTrack, RendererTypeRequester rendererTypeRequester) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(TEXT, rendererTypeRequester);

    DefaultTrackSelector.SelectionOverride selectionOverride = new DefaultTrackSelector.SelectionOverride(
            subtitleTrack.groupIndex(),
            subtitleTrack.formatIndex()
    );
    return trackSelector.setSelectionOverride(TEXT, rendererTypeRequester, trackGroups, selectionOverride);
}
 
Example 7
Source File: ExoPlayerAudioTrackSelectorTest.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Test
public void givenTrackSelectorContainsTracks_whenSelectingAudioTrack_thenSelectsTrack() {
    TrackGroupArray trackGroups = givenTrackSelectorContainsTracks();

    ArgumentCaptor<DefaultTrackSelector.SelectionOverride> argumentCaptor = whenSelectingAudioTrack(trackGroups);

    DefaultTrackSelector.SelectionOverride selectionOverride = argumentCaptor.getValue();
    assertThat(selectionOverride.groupIndex).isEqualTo(SECOND_GROUP);
    assertThat(selectionOverride.tracks).contains(THIRD_TRACK);
}
 
Example 8
Source File: ExoPlayerAudioTrackSelectorTest.java    From no-player with Apache License 2.0 5 votes vote down vote up
private ArgumentCaptor<DefaultTrackSelector.SelectionOverride> whenSelectingAudioTrack(TrackGroupArray trackGroups) {
    exoPlayerAudioTrackSelector.selectAudioTrack(AUDIO_TRACK, rendererTypeRequester);

    ArgumentCaptor<DefaultTrackSelector.SelectionOverride> argumentCaptor = ArgumentCaptor.forClass(DefaultTrackSelector.SelectionOverride.class);
    verify(trackSelector).setSelectionOverride(eq(TrackType.AUDIO), any(RendererTypeRequester.class), eq(trackGroups), argumentCaptor.capture());
    return argumentCaptor;
}
 
Example 9
Source File: ExoPlayerVideoTrackSelectorTest.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Test
public void givenTrackSelectorContainsTracks_whenSelectingVideoTrack_thenSelectsTrack() {
    givenTrackSelectorContainsTracks();

    ArgumentCaptor<DefaultTrackSelector.SelectionOverride> argumentCaptor = whenSelectingVideoTrack(ADDITIONAL_PLAYER_VIDEO_TRACK);

    DefaultTrackSelector.SelectionOverride selectionOverride = argumentCaptor.getValue();
    assertThat(selectionOverride.groupIndex).isEqualTo(FIRST_GROUP);
    assertThat(selectionOverride.tracks).contains(SECOND_TRACK);
}
 
Example 10
Source File: ExoPlayerVideoTrackSelectorTest.java    From no-player with Apache License 2.0 5 votes vote down vote up
private ArgumentCaptor<DefaultTrackSelector.SelectionOverride> whenSelectingVideoTrack(PlayerVideoTrack videoTrack) {
    exoPlayerVideoTrackSelector.selectVideoTrack(videoTrack, rendererTypeRequester);

    ArgumentCaptor<DefaultTrackSelector.SelectionOverride> argumentCaptor = ArgumentCaptor.forClass(DefaultTrackSelector.SelectionOverride.class);
    verify(trackSelector).setSelectionOverride(eq(TrackType.VIDEO), any(RendererTypeRequester.class), any(TrackGroupArray.class), argumentCaptor.capture());
    return argumentCaptor;
}