31
31
import android .widget .TextView ;
32
32
import android .widget .Toast ;
33
33
import androidx .annotation .Nullable ;
34
+ import androidx .annotation .StringRes ;
34
35
import androidx .appcompat .app .AppCompatActivity ;
35
36
import androidx .media3 .common .C ;
36
37
import androidx .media3 .common .MediaItem ;
41
42
import androidx .media3 .transformer .DefaultEncoderFactory ;
42
43
import androidx .media3 .transformer .EncoderSelector ;
43
44
import androidx .media3 .transformer .GlEffect ;
45
+ import androidx .media3 .transformer .GlFrameProcessor ;
44
46
import androidx .media3 .transformer .ProgressHolder ;
45
47
import androidx .media3 .transformer .TransformationException ;
46
48
import androidx .media3 .transformer .TransformationRequest ;
54
56
import com .google .common .collect .ImmutableList ;
55
57
import java .io .File ;
56
58
import java .io .IOException ;
59
+ import java .lang .reflect .Constructor ;
57
60
import java .util .concurrent .CountDownLatch ;
58
61
import java .util .concurrent .TimeUnit ;
59
62
import org .checkerframework .checker .nullness .qual .MonotonicNonNull ;
@@ -249,6 +252,29 @@ private Transformer createTransformer(@Nullable Bundle bundle, String filePath)
249
252
effects .add (MatrixTransformationFactory .createDizzyCropEffect ());
250
253
}
251
254
if (selectedEffects [1 ]) {
255
+ try {
256
+ Class <?> clazz =
257
+ Class .forName ("androidx.media3.demo.transformer.MediaPipeFrameProcessor" );
258
+ Constructor <?> constructor =
259
+ clazz .getConstructor (String .class , String .class , String .class );
260
+ effects .add (
261
+ () -> {
262
+ try {
263
+ return (GlFrameProcessor )
264
+ constructor .newInstance (
265
+ /* graphName= */ "edge_detector_mediapipe_graph.binarypb" ,
266
+ /* inputStreamName= */ "input_video" ,
267
+ /* outputStreamName= */ "output_video" );
268
+ } catch (Exception e ) {
269
+ showToast (R .string .no_media_pipe_error );
270
+ throw new RuntimeException ("Failed to load MediaPipe processor" , e );
271
+ }
272
+ });
273
+ } catch (Exception e ) {
274
+ showToast (R .string .no_media_pipe_error );
275
+ }
276
+ }
277
+ if (selectedEffects [2 ]) {
252
278
effects .add (
253
279
() ->
254
280
new PeriodicVignetteFrameProcessor (
@@ -260,13 +286,13 @@ private Transformer createTransformer(@Nullable Bundle bundle, String filePath)
260
286
ConfigurationActivity .PERIODIC_VIGNETTE_OUTER_RADIUS ),
261
287
bundle .getFloat (ConfigurationActivity .PERIODIC_VIGNETTE_OUTER_RADIUS )));
262
288
}
263
- if (selectedEffects [2 ]) {
289
+ if (selectedEffects [3 ]) {
264
290
effects .add (MatrixTransformationFactory .createSpin3dEffect ());
265
291
}
266
- if (selectedEffects [3 ]) {
292
+ if (selectedEffects [4 ]) {
267
293
effects .add (BitmapOverlayFrameProcessor ::new );
268
294
}
269
- if (selectedEffects [4 ]) {
295
+ if (selectedEffects [5 ]) {
270
296
effects .add (MatrixTransformationFactory .createZoomInTransition ());
271
297
}
272
298
transformerBuilder .setVideoFrameEffects (effects .build ());
@@ -363,6 +389,10 @@ private void requestTransformerPermission() {
363
389
}
364
390
}
365
391
392
+ private void showToast (@ StringRes int messageResource ) {
393
+ Toast .makeText (getApplicationContext (), getString (messageResource ), Toast .LENGTH_LONG ).show ();
394
+ }
395
+
366
396
private final class DemoDebugViewProvider implements Transformer .DebugViewProvider {
367
397
368
398
@ Nullable
0 commit comments