Java Code Examples for com.google.android.exoplayer2.trackselection.DefaultTrackSelector#ParametersBuilder
The following examples show how to use
com.google.android.exoplayer2.trackselection.DefaultTrackSelector#ParametersBuilder .
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: DownloadHelper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * 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()); } } }
Example 2
Source File: DownloadHelper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * 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()); } } }
Example 3
Source File: DownloadHelper.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must * not be called until after preparation completes. * * @param periodIndex The period index the track selection is added for. * @param rendererIndex The renderer index the track selection is added for. * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new * selection of tracks. * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code * trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are. */ public void addTrackSelectionForSingleRenderer( int periodIndex, int rendererIndex, DefaultTrackSelector.Parameters trackSelectorParameters, List<SelectionOverride> overrides) { assertPreparedWithMedia(); DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon(); for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) { builder.setRendererDisabled(/* rendererIndex= */ i, /* disabled= */ i != rendererIndex); } if (overrides.isEmpty()) { addTrackSelection(periodIndex, builder.build()); } else { TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex); for (int i = 0; i < overrides.size(); i++) { builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i)); addTrackSelection(periodIndex, builder.build()); } } }
Example 4
Source File: TrackSelectionHelper.java From leafpicrevived with GNU General Public License v3.0 | 6 votes |
@Override public void onClick(DialogInterface dialog, int which) { DefaultTrackSelector.ParametersBuilder parametersBuilder = DEFAULT_TRACK_SELECTOR_PARAMETERS.buildUpon(); MappedTrackInfo mappedTrackInfo = this.trackInfo; int rendererCount = trackInfo.getRendererCount(); for (int rendererIndex = 0; rendererIndex < rendererCount; rendererIndex++) { if (trackInfo.getRendererType(rendererIndex) != C.TRACK_TYPE_TEXT) { parametersBuilder.setRendererDisabled(rendererIndex, true); } if (override != null) { parametersBuilder.setSelectionOverride(rendererIndex, trackGroups, override); } else { parametersBuilder.clearSelectionOverrides(rendererIndex); } } // @TODO fix this // mappedTrackInfo.setParameters(parametersBuilder.build()); }
Example 5
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 6 votes |
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 6
Source File: DownloadHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * 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.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()); } } }
Example 7
Source File: DownloadHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * 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.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()); } } }
Example 8
Source File: DownloadHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must * not be called until after preparation completes. * * @param periodIndex The period index the track selection is added for. * @param rendererIndex The renderer index the track selection is added for. * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new * selection of tracks. * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code * trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are. */ public void addTrackSelectionForSingleRenderer( int periodIndex, int rendererIndex, DefaultTrackSelector.Parameters trackSelectorParameters, List<SelectionOverride> overrides) { assertPreparedWithMedia(); DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon(); for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) { builder.setRendererDisabled(/* rendererIndex= */ i, /* disabled= */ i != rendererIndex); } if (overrides.isEmpty()) { addTrackSelection(periodIndex, builder.build()); } else { TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex); for (int i = 0; i < overrides.size(); i++) { builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i)); addTrackSelection(periodIndex, builder.build()); } } }
Example 9
Source File: DownloadHelper.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * 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.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()); } } }
Example 10
Source File: DownloadHelper.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * 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.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()); } } }
Example 11
Source File: DownloadHelper.java From Telegram with GNU General Public License v2.0 | 6 votes |
/** * Convenience method to add a selection of tracks to be downloaded for a single renderer. Must * not be called until after preparation completes. * * @param periodIndex The period index the track selection is added for. * @param rendererIndex The renderer index the track selection is added for. * @param trackSelectorParameters The {@link DefaultTrackSelector.Parameters} to obtain the new * selection of tracks. * @param overrides A list of {@link SelectionOverride SelectionOverrides} to apply to the {@code * trackSelectorParameters}. If empty, {@code trackSelectorParameters} are used as they are. */ public void addTrackSelectionForSingleRenderer( int periodIndex, int rendererIndex, DefaultTrackSelector.Parameters trackSelectorParameters, List<SelectionOverride> overrides) { assertPreparedWithMedia(); DefaultTrackSelector.ParametersBuilder builder = trackSelectorParameters.buildUpon(); for (int i = 0; i < mappedTrackInfos[periodIndex].getRendererCount(); i++) { builder.setRendererDisabled(/* rendererIndex= */ i, /* disabled= */ i != rendererIndex); } if (overrides.isEmpty()) { addTrackSelection(periodIndex, builder.build()); } else { TrackGroupArray trackGroupArray = mappedTrackInfos[periodIndex].getTrackGroups(rendererIndex); for (int i = 0; i < overrides.size(); i++) { builder.setSelectionOverride(rendererIndex, trackGroupArray, overrides.get(i)); addTrackSelection(periodIndex, builder.build()); } } }
Example 12
Source File: ExoMediaPlayer.java From ExoMedia with Apache License 2.0 | 5 votes |
/** * Clear all selected tracks for the specified renderer and re-enable all renderers so the player can select the default track. * * @param type The renderer type */ public void clearSelectedTracks(@NonNull RendererType type) { // Retrieves the available tracks MappingTrackSelector.MappedTrackInfo mappedTrackInfo = trackSelector.getCurrentMappedTrackInfo(); ExoPlayerRendererTracksInfo tracksInfo = getExoPlayerTracksInfo(type, 0, mappedTrackInfo); DefaultTrackSelector.ParametersBuilder parametersBuilder = trackSelector.buildUponParameters(); for (int rendererTrackIndex : tracksInfo.rendererTrackIndexes) { // Reset all renderers re-enabling so the player can select the streams default track. parametersBuilder.setRendererDisabled(rendererTrackIndex, false) .clearSelectionOverrides(rendererTrackIndex); } trackSelector.setParameters(parametersBuilder); }