mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
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
82a3fd5dc0
commit
42aaba1f17
@ -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);
|
||||
|
@ -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<Bitmap> future = bitmapLoader.loadBitmap(overlayBitmapUri);
|
||||
try {
|
||||
lastBitmap = future.get();
|
||||
|
Loading…
x
Reference in New Issue
Block a user