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);
}
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);
}
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));
}
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;
}
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;
}
Aggregations