Search in sources :

Example 1 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class DefaultExtractorInputTest method testSkipFullyLarge.

public void testSkipFullyLarge() throws Exception {
    // Tests skipping an amount of data that's larger than any internal scratch space.
    int largeSkipSize = 1024 * 1024;
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    builder.appendReadData(new byte[largeSkipSize]);
    FakeDataSource testDataSource = builder.build();
    testDataSource.open(new DataSpec(Uri.parse(TEST_URI)));
    DefaultExtractorInput input = new DefaultExtractorInput(testDataSource, 0, C.LENGTH_UNSET);
    input.skipFully(largeSkipSize);
    assertEquals(largeSkipSize, input.getPosition());
    // Check that we fail with EOFException we skip again.
    try {
        input.skipFully(1);
        fail();
    } catch (EOFException e) {
    // Expected.
    }
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) EOFException(java.io.EOFException) DataSpec(com.google.android.exoplayer2.upstream.DataSpec)

Example 2 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class CacheDataSourceTest method createCacheDataSource.

private CacheDataSource createCacheDataSource(boolean setReadException, boolean simulateUnknownLength, @CacheDataSource.Flags int flags, CacheDataSink cacheWriteDataSink) {
    FakeDataSource.Builder builder = new FakeDataSource.Builder();
    if (setReadException) {
        builder.appendReadError(new IOException("Shouldn't read from upstream"));
    }
    FakeDataSource upstream = builder.setSimulateUnknownLength(simulateUnknownLength).appendReadData(TEST_DATA).build();
    return new CacheDataSource(simpleCache, upstream, new FileDataSource(), cacheWriteDataSink, flags, null);
}
Also used : FakeDataSource(com.google.android.exoplayer2.testutil.FakeDataSource) FileDataSource(com.google.android.exoplayer2.upstream.FileDataSource) IOException(java.io.IOException)

Example 3 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class PlayerActivity method createMediaItems.

private static List<MediaItem> createMediaItems(Intent intent, DownloadTracker downloadTracker) {
    List<MediaItem> mediaItems = new ArrayList<>();
    for (MediaItem item : IntentUtil.createMediaItemsFromIntent(intent)) {
        @Nullable DownloadRequest downloadRequest = downloadTracker.getDownloadRequest(item.localConfiguration.uri);
        if (downloadRequest != null) {
            MediaItem.Builder builder = item.buildUpon();
            builder.setMediaId(downloadRequest.id).setUri(downloadRequest.uri).setCustomCacheKey(downloadRequest.customCacheKey).setMimeType(downloadRequest.mimeType).setStreamKeys(downloadRequest.streamKeys);
            @Nullable MediaItem.DrmConfiguration drmConfiguration = item.localConfiguration.drmConfiguration;
            if (drmConfiguration != null) {
                builder.setDrmConfiguration(drmConfiguration.buildUpon().setKeySetId(downloadRequest.keySetId).build());
            }
            mediaItems.add(builder.build());
        } else {
            mediaItems.add(item);
        }
    }
    return mediaItems;
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) ArrayList(java.util.ArrayList) DownloadRequest(com.google.android.exoplayer2.offline.DownloadRequest) Nullable(androidx.annotation.Nullable)

Example 4 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class TrackSelectionDialog method createForTrackSelector.

/**
 * Creates a dialog for a given {@link DefaultTrackSelector}, whose parameters will be
 * automatically updated when tracks are selected.
 *
 * @param trackSelector The {@link DefaultTrackSelector}.
 * @param onDismissListener A {@link DialogInterface.OnDismissListener} to call when the dialog is
 *     dismissed.
 */
public static TrackSelectionDialog createForTrackSelector(DefaultTrackSelector trackSelector, DialogInterface.OnDismissListener onDismissListener) {
    MappedTrackInfo mappedTrackInfo = Assertions.checkNotNull(trackSelector.getCurrentMappedTrackInfo());
    TrackSelectionDialog trackSelectionDialog = new TrackSelectionDialog();
    DefaultTrackSelector.Parameters parameters = trackSelector.getParameters();
    trackSelectionDialog.init(/* titleId= */
    R.string.track_selection_title, mappedTrackInfo, /* initialParameters = */
    parameters, /* allowAdaptiveSelections= */
    true, /* allowMultipleOverrides= */
    false, /* onClickListener= */
    (dialog, which) -> {
        DefaultTrackSelector.ParametersBuilder builder = parameters.buildUpon();
        for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
            builder.clearSelectionOverrides(/* rendererIndex= */
            i).setRendererDisabled(/* rendererIndex= */
            i, trackSelectionDialog.getIsDisabled(/* rendererIndex= */
            i));
            List<SelectionOverride> overrides = trackSelectionDialog.getOverrides(/* rendererIndex= */
            i);
            if (!overrides.isEmpty()) {
                builder.setSelectionOverride(/* rendererIndex= */
                i, mappedTrackInfo.getTrackGroups(/* rendererIndex= */
                i), overrides.get(0));
            }
        }
        trackSelector.setParameters(builder);
    }, onDismissListener);
    return trackSelectionDialog;
}
Also used : SelectionOverride(com.google.android.exoplayer2.trackselection.DefaultTrackSelector.SelectionOverride) DefaultTrackSelector(com.google.android.exoplayer2.trackselection.DefaultTrackSelector) MappedTrackInfo(com.google.android.exoplayer2.trackselection.MappingTrackSelector.MappedTrackInfo)

Example 5 with Builder

use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.

the class MediaPeriodQueue method notifyQueueUpdate.

// Internal methods.
private void notifyQueueUpdate() {
    ImmutableList.Builder<MediaPeriodId> builder = ImmutableList.builder();
    @Nullable MediaPeriodHolder period = playing;
    while (period != null) {
        builder.add(period.info.id);
        period = period.getNext();
    }
    @Nullable MediaPeriodId readingPeriodId = reading == null ? null : reading.info.id;
    analyticsCollectorHandler.post(() -> analyticsCollector.updateMediaPeriodQueueInfo(builder.build(), readingPeriodId));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) MediaPeriodId(com.google.android.exoplayer2.source.MediaSource.MediaPeriodId) Nullable(androidx.annotation.Nullable)

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