From eadb78e52a391cdfdd1e70f6cd7441bc82a62e55 Mon Sep 17 00:00:00 2001 From: claincly Date: Fri, 14 Apr 2023 18:42:06 +0100 Subject: [PATCH] Fix crash when there's no input player view. This happens when the input is an image. The output will always be video so the outputPlayer and outputVideoTextView will always present. PiperOrigin-RevId: 524329436 --- .../demo/transformer/TransformerActivity.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java b/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java index de112f29b6..dbd409e222 100644 --- a/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java +++ b/demos/transformer/src/main/java/androidx/media3/demo/transformer/TransformerActivity.java @@ -688,7 +688,6 @@ public final class TransformerActivity extends AppCompatActivity { ExoPlayer outputPlayer = new ExoPlayer.Builder(/* context= */ this).build(); outputPlayerView.setPlayer(outputPlayer); outputPlayerView.setControllerAutoShow(false); - outputPlayerView.setOnClickListener(this::onClickingPlayerView); outputPlayer.setMediaItem(outputMediaItem); outputPlayer.prepare(); this.outputPlayer = outputPlayer; @@ -716,6 +715,7 @@ public final class TransformerActivity extends AppCompatActivity { inputPlayerView.setPlayer(inputPlayer); inputPlayerView.setControllerAutoShow(false); inputPlayerView.setOnClickListener(this::onClickingPlayerView); + outputPlayerView.setOnClickListener(this::onClickingPlayerView); inputPlayer.setMediaItem(inputMediaItem); inputPlayer.prepare(); this.inputPlayer = inputPlayer; @@ -730,13 +730,17 @@ public final class TransformerActivity extends AppCompatActivity { private void onClickingPlayerView(View view) { if (view == inputPlayerView) { - checkNotNull(inputPlayer).setVolume(1f); - checkNotNull(inputTextView).setText(R.string.input_video_playing_sound); + if (inputPlayer != null && inputTextView != null) { + inputPlayer.setVolume(1f); + inputTextView.setText(R.string.input_video_playing_sound); + } checkNotNull(outputPlayer).setVolume(0f); checkNotNull(outputVideoTextView).setText(R.string.output_video_no_sound); } else { - checkNotNull(inputPlayer).setVolume(0f); - checkNotNull(inputTextView).setText(getString(R.string.input_video_no_sound)); + if (inputPlayer != null && inputTextView != null) { + inputPlayer.setVolume(0f); + inputTextView.setText(getString(R.string.input_video_no_sound)); + } checkNotNull(outputPlayer).setVolume(1f); checkNotNull(outputVideoTextView).setText(R.string.output_video_playing_sound); }