Search in sources :

Example 1 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class DefaultMediaSourceFactory method maybeWrapWithAdsMediaSource.

private MediaSource maybeWrapWithAdsMediaSource(MediaItem mediaItem, MediaSource mediaSource) {
    checkNotNull(mediaItem.localConfiguration);
    @Nullable MediaItem.AdsConfiguration adsConfiguration = mediaItem.localConfiguration.adsConfiguration;
    if (adsConfiguration == null) {
        return mediaSource;
    }
    @Nullable AdsLoader.Provider adsLoaderProvider = this.adsLoaderProvider;
    @Nullable AdViewProvider adViewProvider = this.adViewProvider;
    if (adsLoaderProvider == null || adViewProvider == null) {
        Log.w(TAG, "Playing media without ads. Configure ad support by calling setAdsLoaderProvider and" + " setAdViewProvider.");
        return mediaSource;
    }
    @Nullable AdsLoader adsLoader = adsLoaderProvider.getAdsLoader(adsConfiguration);
    if (adsLoader == null) {
        Log.w(TAG, "Playing media without ads, as no AdsLoader was provided.");
        return mediaSource;
    }
    return new AdsMediaSource(mediaSource, new DataSpec(adsConfiguration.adTagUri), /* adsId= */
    adsConfiguration.adsId != null ? adsConfiguration.adsId : ImmutableList.of(mediaItem.mediaId, mediaItem.localConfiguration.uri, adsConfiguration.adTagUri), /* adMediaSourceFactory= */
    this, adsLoader, adViewProvider);
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem) AdViewProvider(com.google.android.exoplayer2.ui.AdViewProvider) AdsMediaSource(com.google.android.exoplayer2.source.ads.AdsMediaSource) DataSpec(com.google.android.exoplayer2.upstream.DataSpec) Nullable(androidx.annotation.Nullable) AdsLoader(com.google.android.exoplayer2.source.ads.AdsLoader)

Example 2 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class MediaItemTest method builderSetStreamKeys_setsStreamKeys.

@Test
public void builderSetStreamKeys_setsStreamKeys() {
    List<StreamKey> streamKeys = new ArrayList<>();
    streamKeys.add(new StreamKey(1, 0, 0));
    streamKeys.add(new StreamKey(0, 1, 1));
    MediaItem mediaItem = new MediaItem.Builder().setUri(URI_STRING).setStreamKeys(streamKeys).build();
    assertThat(mediaItem.localConfiguration.streamKeys).isEqualTo(streamKeys);
}
Also used : ArrayList(java.util.ArrayList) StreamKey(com.google.android.exoplayer2.offline.StreamKey) Test(org.junit.Test)

Example 3 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class DefaultAnalyticsCollector method onMediaItemTransition.

@Override
public final void onMediaItemTransition(@Nullable MediaItem mediaItem, @Player.MediaItemTransitionReason int reason) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, AnalyticsListener.EVENT_MEDIA_ITEM_TRANSITION, listener -> listener.onMediaItemTransition(eventTime, mediaItem, reason));
}
Also used : EventTime(com.google.android.exoplayer2.analytics.AnalyticsListener.EventTime)

Example 4 with MediaItem

use of com.google.android.exoplayer2.MediaItem in project ExoPlayer by google.

the class PlayerActivity method createMediaItems.

private List<MediaItem> createMediaItems(Intent intent) {
    String action = intent.getAction();
    boolean actionIsListView = IntentUtil.ACTION_VIEW_LIST.equals(action);
    if (!actionIsListView && !IntentUtil.ACTION_VIEW.equals(action)) {
        showToast(getString(R.string.unexpected_intent_action, action));
        finish();
        return Collections.emptyList();
    }
    List<MediaItem> mediaItems = createMediaItems(intent, DemoUtil.getDownloadTracker(/* context= */
    this));
    for (int i = 0; i < mediaItems.size(); i++) {
        MediaItem mediaItem = mediaItems.get(i);
        if (!Util.checkCleartextTrafficPermitted(mediaItem)) {
            showToast(R.string.error_cleartext_not_permitted);
            finish();
            return Collections.emptyList();
        }
        if (Util.maybeRequestReadExternalStoragePermission(/* activity= */
        this, mediaItem)) {
            // The player will be reinitialized if the permission is granted.
            return Collections.emptyList();
        }
        MediaItem.DrmConfiguration drmConfiguration = mediaItem.localConfiguration.drmConfiguration;
        if (drmConfiguration != null) {
            if (Util.SDK_INT < 18) {
                showToast(R.string.error_drm_unsupported_before_api_18);
                finish();
                return Collections.emptyList();
            } else if (!FrameworkMediaDrm.isCryptoSchemeSupported(drmConfiguration.scheme)) {
                showToast(R.string.error_drm_unsupported_scheme);
                finish();
                return Collections.emptyList();
            }
        }
    }
    return mediaItems;
}
Also used : MediaItem(com.google.android.exoplayer2.MediaItem)

Example 5 with MediaItem

use of com.google.android.exoplayer2.MediaItem 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)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)158 Test (org.junit.Test)151 MediaSource (com.google.android.exoplayer2.source.MediaSource)29 ArrayList (java.util.ArrayList)29 Timeline (com.google.android.exoplayer2.Timeline)25 InOrder (org.mockito.InOrder)20 Nullable (androidx.annotation.Nullable)19 TestExoPlayerBuilder (com.google.android.exoplayer2.testutil.TestExoPlayerBuilder)19 Player (com.google.android.exoplayer2.Player)17 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)17 Listener (com.google.android.exoplayer2.Player.Listener)15 TestPlayerRunHelper.playUntilStartOfMediaItem (com.google.android.exoplayer2.robolectric.TestPlayerRunHelper.playUntilStartOfMediaItem)15 DefaultMediaSourceFactory (com.google.android.exoplayer2.source.DefaultMediaSourceFactory)15 Uri (android.net.Uri)13 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)13 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)13 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)13 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)12 ClippingMediaSource (com.google.android.exoplayer2.source.ClippingMediaSource)12