From cf7b908e948c040ccb10365476df74c4ceb2004f Mon Sep 17 00:00:00 2001 From: tonihei Date: Thu, 16 Jan 2020 10:32:41 +0000 Subject: [PATCH] Fix demo app NPE when selecting unsupported samples. PiperOrigin-RevId: 290027772 --- .../android/exoplayer2/demo/PlayerActivity.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java b/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java index b759c97da5..83d50bfcc4 100644 --- a/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java +++ b/demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java @@ -82,6 +82,7 @@ import java.net.CookieHandler; import java.net.CookieManager; import java.net.CookiePolicy; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** An activity that plays media using {@link SimpleExoPlayer}. */ @@ -405,7 +406,7 @@ public class PlayerActivity extends AppCompatActivity if (!actionIsListView && !ACTION_VIEW.equals(action)) { showToast(getString(R.string.unexpected_intent_action, action)); finish(); - return null; + return Collections.emptyList(); } Sample intentAsSample = Sample.createFromIntent(intent); @@ -419,17 +420,20 @@ public class PlayerActivity extends AppCompatActivity seenAdsTagUri |= sample.adTagUri != null; if (!Util.checkCleartextTrafficPermitted(sample.uri)) { showToast(R.string.error_cleartext_not_permitted); - return null; + return Collections.emptyList(); } if (Util.maybeRequestReadExternalStoragePermission(/* activity= */ this, sample.uri)) { // The player will be reinitialized if the permission is granted. - return null; + return Collections.emptyList(); } } List mediaSources = new ArrayList<>(); for (UriSample sample : samples) { MediaSource mediaSource = createLeafMediaSource(sample); + if (mediaSource == null) { + continue; + } Sample.SubtitleInfo subtitleInfo = sample.subtitleInfo; if (subtitleInfo != null) { Format subtitleFormat = @@ -467,6 +471,7 @@ public class PlayerActivity extends AppCompatActivity return mediaSources; } + @Nullable private MediaSource createLeafMediaSource(UriSample parameters) { Sample.DrmInfo drmInfo = parameters.drmInfo; int errorStringId = R.string.error_drm_unknown; @@ -602,7 +607,7 @@ public class PlayerActivity extends AppCompatActivity try { Class loaderClass = Class.forName("com.google.android.exoplayer2.ext.ima.ImaAdsLoader"); if (adsLoader == null) { - // Full class names used so the LINT.IfChange rule triggers should any of the classes move. + // Full class names used so the lint rule triggers should any of the classes move. // LINT.IfChange Constructor loaderConstructor = loaderClass