Search in sources :

Example 1 with ParametersBuilder

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

the class DownloadHelper method addAudioLanguagesToSelection.

/**
 * Convenience method to add selections of tracks for all specified audio languages. If an audio
 * track in one of the specified languages is not available, the default fallback audio track is
 * used instead. Must not be called until after preparation completes.
 *
 * @param languages A list of audio languages for which tracks should be added to the download
 *     selection, as IETF BCP 47 conformant tags.
 */
public void addAudioLanguagesToSelection(String... languages) {
    assertPreparedWithMedia();
    for (int periodIndex = 0; periodIndex < mappedTrackInfos.length; periodIndex++) {
        DefaultTrackSelector.ParametersBuilder parametersBuilder = DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT.buildUpon();
        MappedTrackInfo mappedTrackInfo = mappedTrackInfos[periodIndex];
        int rendererCount = mappedTrackInfo.getRendererCount();
        for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
            if (mappedTrackInfo.getRendererType(rendererIndex) != C.TRACK_TYPE_AUDIO) {
                parametersBuilder.setRendererDisabled(rendererIndex, /* disabled= */
                true);
            }
        }
        for (String language : languages) {
            parametersBuilder.setPreferredAudioLanguage(language);
            addTrackSelection(periodIndex, parametersBuilder.build());
        }
    }
}
Also used : DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Example 2 with ParametersBuilder

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

the class DefaultTrackSelectorTest method setParameterWithSameParametersDoesNotNotifyInvalidationListenerAgain.

/**
 * Tests that track selector will not call {@link
 * InvalidationListener#onTrackSelectionsInvalidated()} again when it's set with the same values
 * of {@link Parameters}.
 */
@Test
public void setParameterWithSameParametersDoesNotNotifyInvalidationListenerAgain() {
    ParametersBuilder builder = defaultParameters.buildUpon().setPreferredAudioLanguage("eng");
    trackSelector.setParameters(builder);
    trackSelector.setParameters(builder);
    verify(invalidationListener, times(1)).onTrackSelectionsInvalidated();
}
Also used : ParametersBuilder(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder) Test(org.junit.Test)

Example 3 with ParametersBuilder

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

the class DefaultTrackSelectorTest method setParameterWithNonDefaultParameterNotifyInvalidationListener.

/**
 * Tests that track selector will call {@link InvalidationListener#onTrackSelectionsInvalidated()}
 * when it's set with non-default values of {@link Parameters}.
 */
@Test
public void setParameterWithNonDefaultParameterNotifyInvalidationListener() {
    ParametersBuilder builder = defaultParameters.buildUpon().setPreferredAudioLanguage("eng");
    trackSelector.setParameters(builder);
    verify(invalidationListener).onTrackSelectionsInvalidated();
}
Also used : ParametersBuilder(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder) Test(org.junit.Test)

Example 4 with ParametersBuilder

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

the class DefaultTrackSelectorTest method selectUndeterminedTextLanguageAsFallback.

/**
 * Tests that the default track selector will select a text track with undetermined language if no
 * text track with the preferred language is available but {@link
 * Parameters#selectUndeterminedTextLanguage} is true.
 */
@Test
public void selectUndeterminedTextLanguageAsFallback() throws ExoPlaybackException {
    Format.Builder formatBuilder = TEXT_FORMAT.buildUpon();
    Format spanish = formatBuilder.setLanguage("spa").build();
    Format german = formatBuilder.setLanguage("de").build();
    Format undeterminedUnd = formatBuilder.setLanguage(C.LANGUAGE_UNDETERMINED).build();
    Format undeterminedNull = formatBuilder.setLanguage(null).build();
    RendererCapabilities[] textRendererCapabilites = new RendererCapabilities[] { ALL_TEXT_FORMAT_SUPPORTED_RENDERER_CAPABILITIES };
    TrackGroupArray trackGroups = wrapFormats(spanish, german, undeterminedUnd, undeterminedNull);
    TrackSelectorResult result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
    trackSelector.setParameters(defaultParameters.buildUpon().setSelectUndeterminedTextLanguage(true));
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, undeterminedUnd);
    ParametersBuilder builder = defaultParameters.buildUpon().setPreferredTextLanguage("spa");
    trackSelector.setParameters(builder);
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, spanish);
    trackGroups = wrapFormats(german, undeterminedUnd, undeterminedNull);
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
    trackSelector.setParameters(builder.setSelectUndeterminedTextLanguage(true));
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, undeterminedUnd);
    trackGroups = wrapFormats(german, undeterminedNull);
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertFixedSelection(result.selections[0], trackGroups, undeterminedNull);
    trackGroups = wrapFormats(german);
    result = trackSelector.selectTracks(textRendererCapabilites, trackGroups, periodId, TIMELINE);
    assertNoSelection(result.selections[0]);
}
Also used : ParametersBuilder(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder) Format(com.google.android.exoplayer2.Format) TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) RendererCapabilities(com.google.android.exoplayer2.RendererCapabilities) Test(org.junit.Test)

Example 5 with ParametersBuilder

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

the class DownloadHelper method addTextLanguagesToSelection.

/**
 * Convenience method to add selections of tracks for all specified text languages. Must not be
 * called until after preparation completes.
 *
 * @param selectUndeterminedTextLanguage Whether a text track with undetermined language should be
 *     selected for downloading if no track with one of the specified {@code languages} is
 *     available.
 * @param languages A list of text languages for which tracks should be added to the download
 *     selection, as IETF BCP 47 conformant tags.
 */
public void addTextLanguagesToSelection(boolean selectUndeterminedTextLanguage, String... languages) {
    assertPreparedWithMedia();
    for (int periodIndex = 0; periodIndex < mappedTrackInfos.length; periodIndex++) {
        DefaultTrackSelector.ParametersBuilder parametersBuilder = DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_CONTEXT.buildUpon();
        MappedTrackInfo mappedTrackInfo = mappedTrackInfos[periodIndex];
        int rendererCount = mappedTrackInfo.getRendererCount();
        for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) {
            if (mappedTrackInfo.getRendererType(rendererIndex) != C.TRACK_TYPE_TEXT) {
                parametersBuilder.setRendererDisabled(rendererIndex, /* disabled= */
                true);
            }
        }
        parametersBuilder.setSelectUndeterminedTextLanguage(selectUndeterminedTextLanguage);
        for (String language : languages) {
            parametersBuilder.setPreferredTextLanguage(language);
            addTrackSelection(periodIndex, parametersBuilder.build());
        }
    }
}
Also used : DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Aggregations

ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)3 Test (org.junit.Test)3 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)2 MappedTrackInfo (com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)2 Format (com.google.android.exoplayer2.Format)1 RendererCapabilities (com.google.android.exoplayer2.RendererCapabilities)1 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)1