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 b3023ffe9a
commit 68578be372
2 changed files with 5 additions and 7 deletions

View File

@ -593,6 +593,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);

View File

@ -16,8 +16,8 @@
package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import android.content.Context;
import android.graphics.Bitmap;
import android.net.Uri;
import android.opengl.GLES20;
@ -28,7 +28,6 @@ import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Size;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DataSourceBitmapLoader;
import androidx.media3.datasource.DefaultHttpDataSource;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@ -130,22 +129,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<Bitmap> future = bitmapLoader.loadBitmap(overlayBitmapUri);
try {
lastBitmap = future.get();