Commit 67294609 by kimvde Committed by Marc Baechinger

Demo app fixes

- Do not fail silently if selectedEffects is null.
- Do not add an empty overlay effect to the Transformer to avoid
  transcoding video all the time.

PiperOrigin-RevId: 499168759
parent 09d43114
...@@ -19,6 +19,7 @@ import static android.Manifest.permission.READ_EXTERNAL_STORAGE; ...@@ -19,6 +19,7 @@ import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED; import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STATE_NOT_STARTED;
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.checkState; import static com.google.android.exoplayer2.util.Assertions.checkState;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
...@@ -383,12 +384,8 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -383,12 +384,8 @@ public final class TransformerActivity extends AppCompatActivity {
private ImmutableList<Effect> createVideoEffectsFromBundle(Bundle bundle) private ImmutableList<Effect> createVideoEffectsFromBundle(Bundle bundle)
throws PackageManager.NameNotFoundException { throws PackageManager.NameNotFoundException {
@Nullable
boolean[] selectedEffects = boolean[] selectedEffects =
bundle.getBooleanArray(ConfigurationActivity.VIDEO_EFFECTS_SELECTIONS); checkStateNotNull(bundle.getBooleanArray(ConfigurationActivity.VIDEO_EFFECTS_SELECTIONS));
if (selectedEffects == null) {
return ImmutableList.of();
}
ImmutableList.Builder<Effect> effects = new ImmutableList.Builder<>(); ImmutableList.Builder<Effect> effects = new ImmutableList.Builder<>();
if (selectedEffects[ConfigurationActivity.DIZZY_CROP_INDEX]) { if (selectedEffects[ConfigurationActivity.DIZZY_CROP_INDEX]) {
effects.add(MatrixTransformationFactory.createDizzyCropEffect()); effects.add(MatrixTransformationFactory.createDizzyCropEffect());
...@@ -508,13 +505,18 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -508,13 +505,18 @@ public final class TransformerActivity extends AppCompatActivity {
effects.add(MatrixTransformationFactory.createZoomInTransition()); effects.add(MatrixTransformationFactory.createZoomInTransition());
} }
effects.add(createOverlayEffectFromBundle(bundle, selectedEffects)); @Nullable OverlayEffect overlayEffect = createOverlayEffectFromBundle(bundle, selectedEffects);
if (overlayEffect != null) {
effects.add(overlayEffect);
}
return effects.build(); return effects.build();
} }
@Nullable
private OverlayEffect createOverlayEffectFromBundle(Bundle bundle, boolean[] selectedEffects) private OverlayEffect createOverlayEffectFromBundle(Bundle bundle, boolean[] selectedEffects)
throws PackageManager.NameNotFoundException { throws PackageManager.NameNotFoundException {
ImmutableList.Builder<TextureOverlay> overlays = new ImmutableList.Builder<>(); ImmutableList.Builder<TextureOverlay> overlaysBuilder = new ImmutableList.Builder<>();
if (selectedEffects[ConfigurationActivity.OVERLAY_LOGO_AND_TIMER_INDEX]) { if (selectedEffects[ConfigurationActivity.OVERLAY_LOGO_AND_TIMER_INDEX]) {
float[] logoPositioningMatrix = GlUtil.create4x4IdentityMatrix(); float[] logoPositioningMatrix = GlUtil.create4x4IdentityMatrix();
Matrix.translateM( Matrix.translateM(
...@@ -529,7 +531,7 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -529,7 +531,7 @@ public final class TransformerActivity extends AppCompatActivity {
/* left= */ 0, /* top= */ 0, logo.getIntrinsicWidth(), logo.getIntrinsicHeight()); /* left= */ 0, /* top= */ 0, logo.getIntrinsicWidth(), logo.getIntrinsicHeight());
TextureOverlay logoOverlay = DrawableOverlay.createStaticDrawableOverlay(logo, logoSettings); TextureOverlay logoOverlay = DrawableOverlay.createStaticDrawableOverlay(logo, logoSettings);
TextureOverlay timerOverlay = new TimerOverlay(); TextureOverlay timerOverlay = new TimerOverlay();
overlays.add(logoOverlay, timerOverlay); overlaysBuilder.add(logoOverlay, timerOverlay);
} }
if (selectedEffects[ConfigurationActivity.BITMAP_OVERLAY_INDEX]) { if (selectedEffects[ConfigurationActivity.BITMAP_OVERLAY_INDEX]) {
OverlaySettings overlaySettings = OverlaySettings overlaySettings =
...@@ -542,7 +544,7 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -542,7 +544,7 @@ public final class TransformerActivity extends AppCompatActivity {
BitmapOverlay.createStaticBitmapOverlay( BitmapOverlay.createStaticBitmapOverlay(
Uri.parse(checkNotNull(bundle.getString(ConfigurationActivity.BITMAP_OVERLAY_URI))), Uri.parse(checkNotNull(bundle.getString(ConfigurationActivity.BITMAP_OVERLAY_URI))),
overlaySettings); overlaySettings);
overlays.add(bitmapOverlay); overlaysBuilder.add(bitmapOverlay);
} }
if (selectedEffects[ConfigurationActivity.TEXT_OVERLAY_INDEX]) { if (selectedEffects[ConfigurationActivity.TEXT_OVERLAY_INDEX]) {
OverlaySettings overlaySettings = OverlaySettings overlaySettings =
...@@ -559,9 +561,11 @@ public final class TransformerActivity extends AppCompatActivity { ...@@ -559,9 +561,11 @@ public final class TransformerActivity extends AppCompatActivity {
overlayText.length(), overlayText.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TextOverlay textOverlay = TextOverlay.createStaticTextOverlay(overlayText, overlaySettings); TextOverlay textOverlay = TextOverlay.createStaticTextOverlay(overlayText, overlaySettings);
overlays.add(textOverlay); overlaysBuilder.add(textOverlay);
} }
return new OverlayEffect(overlays.build());
ImmutableList<TextureOverlay> overlays = overlaysBuilder.build();
return overlays.isEmpty() ? null : new OverlayEffect(overlays);
} }
@RequiresNonNull({ @RequiresNonNull({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment