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:
parent
b3023ffe9a
commit
68578be372
@ -593,6 +593,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);
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
package androidx.media3.effect;
|
package androidx.media3.effect;
|
||||||
|
|
||||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
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.graphics.Bitmap;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.opengl.GLES20;
|
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.Size;
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.datasource.DataSourceBitmapLoader;
|
import androidx.media3.datasource.DataSourceBitmapLoader;
|
||||||
import androidx.media3.datasource.DefaultHttpDataSource;
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
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
|
* 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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user