use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class IntentUtil method createMediaItemFromIntent.
private static MediaItem createMediaItemFromIntent(Uri uri, Intent intent, String extrasKeySuffix) {
@Nullable String mimeType = intent.getStringExtra(MIME_TYPE_EXTRA + extrasKeySuffix);
@Nullable String title = intent.getStringExtra(TITLE_EXTRA + extrasKeySuffix);
@Nullable String adTagUri = intent.getStringExtra(AD_TAG_URI_EXTRA + extrasKeySuffix);
@Nullable SubtitleConfiguration subtitleConfiguration = createSubtitleConfiguration(intent, extrasKeySuffix);
MediaItem.Builder builder = new MediaItem.Builder().setUri(uri).setMimeType(mimeType).setMediaMetadata(new MediaMetadata.Builder().setTitle(title).build()).setClippingConfiguration(new ClippingConfiguration.Builder().setStartPositionMs(intent.getLongExtra(CLIP_START_POSITION_MS_EXTRA + extrasKeySuffix, 0)).setEndPositionMs(intent.getLongExtra(CLIP_END_POSITION_MS_EXTRA + extrasKeySuffix, C.TIME_END_OF_SOURCE)).build());
if (adTagUri != null) {
builder.setAdsConfiguration(new MediaItem.AdsConfiguration.Builder(Uri.parse(adTagUri)).build());
}
if (subtitleConfiguration != null) {
builder.setSubtitleConfigurations(ImmutableList.of(subtitleConfiguration));
}
return populateDrmPropertiesFromIntent(builder, intent, extrasKeySuffix).build();
}
use of com.google.android.exoplayer2.DefaultLoadControl.Builder 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]);
}
use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class TestExoPlayerBuilder method build.
/**
* Builds an {@link ExoPlayer} using the provided values or their defaults.
*/
public ExoPlayer build() {
Assertions.checkNotNull(looper, "TestExoPlayer builder run on a thread without Looper and no Looper specified.");
// Do not update renderersFactory and renderers here, otherwise their getters may
// return different values before and after build() is called, making them confusing.
RenderersFactory playerRenderersFactory = renderersFactory;
if (playerRenderersFactory == null) {
playerRenderersFactory = (eventHandler, videoRendererEventListener, audioRendererEventListener, textRendererOutput, metadataRendererOutput) -> renderers != null ? renderers : new Renderer[] { new FakeVideoRenderer(eventHandler, videoRendererEventListener), new FakeAudioRenderer(eventHandler, audioRendererEventListener) };
}
ExoPlayer.Builder builder = new ExoPlayer.Builder(context, playerRenderersFactory).setTrackSelector(trackSelector).setLoadControl(loadControl).setBandwidthMeter(bandwidthMeter).setAnalyticsCollector(new DefaultAnalyticsCollector(clock)).setClock(clock).setUseLazyPreparation(useLazyPreparation).setLooper(looper).setSeekBackIncrementMs(seekBackIncrementMs).setSeekForwardIncrementMs(seekForwardIncrementMs);
if (mediaSourceFactory != null) {
builder.setMediaSourceFactory(mediaSourceFactory);
}
return builder.build();
}
use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class DownloadHelper method addTrackSelectionForSingleRenderer.
/**
* 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());
}
}
}
use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class BundleableUtil method toBundleList.
/**
* Converts a list of {@link Bundleable} to a list {@link Bundle}.
*/
public static <T extends Bundleable> ImmutableList<Bundle> toBundleList(List<T> bundleableList) {
ImmutableList.Builder<Bundle> builder = ImmutableList.builder();
for (int i = 0; i < bundleableList.size(); i++) {
Bundleable bundleable = bundleableList.get(i);
builder.add(bundleable.toBundle());
}
return builder.build();
}
Aggregations