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
This commit is contained in:
tofunmi 2023-03-08 13:49:01 +00:00 committed by tonihei
parent 82a3fd5dc0
commit 42aaba1f17
2 changed files with 5 additions and 7 deletions

View File

@ -594,6 +594,7 @@ public final class TransformerActivity extends AppCompatActivity {
.build(); .build();
BitmapOverlay bitmapOverlay = BitmapOverlay bitmapOverlay =
BitmapOverlay.createStaticBitmapOverlay( BitmapOverlay.createStaticBitmapOverlay(
getApplicationContext(),
Uri.parse(checkNotNull(bundle.getString(ConfigurationActivity.BITMAP_OVERLAY_URI))), Uri.parse(checkNotNull(bundle.getString(ConfigurationActivity.BITMAP_OVERLAY_URI))),
overlaySettings); overlaySettings);
overlaysBuilder.add(bitmapOverlay); overlaysBuilder.add(bitmapOverlay);

View File

@ -16,14 +16,13 @@
package com.google.android.exoplayer2.effect; package com.google.android.exoplayer2.effect;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull; 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.graphics.Bitmap;
import android.net.Uri; import android.net.Uri;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.GLUtils; import android.opengl.GLUtils;
import com.google.android.exoplayer2.upstream.DataSourceBitmapLoader; 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.BitmapLoader;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import com.google.android.exoplayer2.util.Size; 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 * Creates a {@link BitmapOverlay} that shows the input at {@code overlayBitmapUri} with the same
* {@link OverlaySettings} throughout the whole video. * {@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 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 * @param overlaySettings The {@link OverlaySettings} configuring how the overlay is displayed on
* the frames. * the frames.
*/ */
public static BitmapOverlay createStaticBitmapOverlay( public static BitmapOverlay createStaticBitmapOverlay(
Uri overlayBitmapUri, OverlaySettings overlaySettings) { Context context, Uri overlayBitmapUri, OverlaySettings overlaySettings) {
return new BitmapOverlay() { return new BitmapOverlay() {
private @MonotonicNonNull Bitmap lastBitmap; private @MonotonicNonNull Bitmap lastBitmap;
@Override @Override
public Bitmap getBitmap(long presentationTimeUs) throws VideoFrameProcessingException { public Bitmap getBitmap(long presentationTimeUs) throws VideoFrameProcessingException {
if (lastBitmap == null) { if (lastBitmap == null) {
BitmapLoader bitmapLoader = BitmapLoader bitmapLoader = new DataSourceBitmapLoader(context);
new DataSourceBitmapLoader(
checkStateNotNull(DataSourceBitmapLoader.DEFAULT_EXECUTOR_SERVICE.get()),
new DefaultHttpDataSource.Factory());
ListenableFuture<Bitmap> future = bitmapLoader.loadBitmap(overlayBitmapUri); ListenableFuture<Bitmap> future = bitmapLoader.loadBitmap(overlayBitmapUri);
try { try {
lastBitmap = future.get(); lastBitmap = future.get();