Search in sources :

Example 26 with Builder

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();
}
Also used : SubtitleConfiguration(com.google.android.exoplayer2.MediaItem.SubtitleConfiguration) MediaItem(com.google.android.exoplayer2.MediaItem) Nullable(androidx.annotation.Nullable)

Example 27 with Builder

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]);
}
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 28 with Builder

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();
}
Also used : Renderer(com.google.android.exoplayer2.Renderer) RenderersFactory(com.google.android.exoplayer2.RenderersFactory) ExoPlayer(com.google.android.exoplayer2.ExoPlayer) DefaultAnalyticsCollector(com.google.android.exoplayer2.analytics.DefaultAnalyticsCollector)

Example 29 with Builder

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());
        }
    }
}
Also used : TrackGroupArray(com.google.android.exoplayer2.source.TrackGroupArray) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector)

Example 30 with Builder

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();
}
Also used : Bundleable(com.google.android.exoplayer2.Bundleable) ImmutableList(com.google.common.collect.ImmutableList) Bundle(android.os.Bundle)

Aggregations

Test (org.junit.Test)12 Nullable (androidx.annotation.Nullable)7 MediaItem (com.google.android.exoplayer2.MediaItem)6 MediaMetadata (com.google.android.exoplayer2.MediaMetadata)5 Metadata (com.google.android.exoplayer2.metadata.Metadata)4 TrackGroupArray (com.google.android.exoplayer2.source.TrackGroupArray)3 ParametersBuilder (com.google.android.exoplayer2.trackselection.DefaultTrackSelector.ParametersBuilder)3 ImmutableList (com.google.common.collect.ImmutableList)3 Bundle (android.os.Bundle)2 FakeDataSource (com.google.android.exoplayer2.testutil.FakeDataSource)2 DefaultTrackSelector (com.google.android.exoplayer2.trackselection.DefaultTrackSelector)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)2 MediaQueueItem (com.google.android.gms.cast.MediaQueueItem)2 SurfaceTexture (android.graphics.SurfaceTexture)1 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)1 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)1 BackgroundColorSpan (android.text.style.BackgroundColorSpan)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 RelativeSizeSpan (android.text.style.RelativeSizeSpan)1 StrikethroughSpan (android.text.style.StrikethroughSpan)1