From 42aaba1f17f3f4b37edcb486ae779130c881a7f5 Mon Sep 17 00:00:00 2001 From: tofunmi Date: Wed, 8 Mar 2023 13:49:01 +0000 Subject: [PATCH] Update createStaticBitmapOverlay to take in context. By making this method accept context, we can use DefaultDataSource.Factory in the DatasourceBitmapLoader to support a wider range on URI schemes in Bitmap Overlays. (and implement a local file picker for images for custom bitmap overlays in the demo transformer app) PiperOrigin-RevId: 515013460 --- .../transformerdemo/TransformerActivity.java | 1 + .../android/exoplayer2/effect/BitmapOverlay.java | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java b/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java index 21af40af49..330c329c60 100644 --- a/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java +++ b/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java @@ -594,6 +594,7 @@ public final class TransformerActivity extends AppCompatActivity { .build(); BitmapOverlay bitmapOverlay = BitmapOverlay.createStaticBitmapOverlay( + getApplicationContext(), Uri.parse(checkNotNull(bundle.getString(ConfigurationActivity.BITMAP_OVERLAY_URI))), overlaySettings); overlaysBuilder.add(bitmapOverlay); diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/BitmapOverlay.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/BitmapOverlay.java index 34007d92df..8b95ee485b 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/BitmapOverlay.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/BitmapOverlay.java @@ -16,14 +16,13 @@ package com.google.android.exoplayer2.effect; import static com.google.android.exoplayer2.util.Assertions.checkNotNull; -import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull; +import android.content.Context; import android.graphics.Bitmap; import android.net.Uri; import android.opengl.GLES20; import android.opengl.GLUtils; import com.google.android.exoplayer2.upstream.DataSourceBitmapLoader; -import com.google.android.exoplayer2.upstream.DefaultHttpDataSource; import com.google.android.exoplayer2.util.BitmapLoader; import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.Size; @@ -128,22 +127,20 @@ public abstract class BitmapOverlay extends TextureOverlay { * Creates a {@link BitmapOverlay} that shows the input at {@code overlayBitmapUri} with the same * {@link OverlaySettings} throughout the whole video. * + * @param context The {@link Context}. * @param overlayBitmapUri The {@link Uri} pointing to the resource to be converted into a bitmap. * @param overlaySettings The {@link OverlaySettings} configuring how the overlay is displayed on * the frames. */ public static BitmapOverlay createStaticBitmapOverlay( - Uri overlayBitmapUri, OverlaySettings overlaySettings) { + Context context, Uri overlayBitmapUri, OverlaySettings overlaySettings) { return new BitmapOverlay() { private @MonotonicNonNull Bitmap lastBitmap; @Override public Bitmap getBitmap(long presentationTimeUs) throws VideoFrameProcessingException { if (lastBitmap == null) { - BitmapLoader bitmapLoader = - new DataSourceBitmapLoader( - checkStateNotNull(DataSourceBitmapLoader.DEFAULT_EXECUTOR_SERVICE.get()), - new DefaultHttpDataSource.Factory()); + BitmapLoader bitmapLoader = new DataSourceBitmapLoader(context); ListenableFuture future = bitmapLoader.loadBitmap(overlayBitmapUri); try { lastBitmap = future.get();