[Android] Audioplayer: avoid NPE

Geoffrey Métais git at videolan.org
Wed Sep 12 10:52:00 CEST 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Sep 12 10:51:39 2018 +0200| [e86c5536059d4f76b07ecf93edf13426e35d41b1] | committer: Geoffrey Métais

Audioplayer: avoid NPE

> https://code.videolan.org/videolan/vlc-android/commit/e86c5536059d4f76b07ecf93edf13426e35d41b1
---

 vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt        | 9 ++++-----
 .../src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java        | 6 +++---
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
index 02860c918..5f8159dc5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.kt
@@ -202,12 +202,11 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, PlaybackSe
                 switchToVideo()
                 return
             }
-        }
-
-        binding.audioMediaSwitcher.updateMedia(service)
-        binding.coverMediaSwitcher.updateMedia(service)
+            binding.audioMediaSwitcher.updateMedia(this)
+            binding.coverMediaSwitcher.updateMedia(this)
 
-        binding.playlistPlayasaudioOff.visibility = if (service?.videoTracksCount ?: 0 > 0) View.VISIBLE else View.GONE
+            binding.playlistPlayasaudioOff.visibility = if (videoTracksCount > 0) View.VISIBLE else View.GONE
+        }
 
         updatePlayPause()
         updateShuffleMode()
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java b/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java
index be885e6b4..5a8d81afd 100644
--- a/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java
+++ b/vlc-android/src/org/videolan/vlc/gui/view/AudioMediaSwitcher.java
@@ -51,9 +51,9 @@ public abstract class AudioMediaSwitcher extends FlingViewGroup {
         WorkersKt.runBackground(new Runnable() {
             @Override
             public void run() {
-                final Bitmap coverCurrent = AudioUtil.readCoverBitmap(Uri.decode(artMrl), 512);
-                final Bitmap coverPrev = AudioUtil.readCoverBitmap(Uri.decode(prevArtMrl), 512);
-                final Bitmap coverNext = AudioUtil.readCoverBitmap(Uri.decode(nextArtMrl), 512);
+                final Bitmap coverCurrent = artMrl != null ? AudioUtil.readCoverBitmap(Uri.decode(artMrl), 512) : null;
+                final Bitmap coverPrev = prevArtMrl != null ? AudioUtil.readCoverBitmap(Uri.decode(prevArtMrl), 512) : null;
+                final Bitmap coverNext = nextArtMrl != null ? AudioUtil.readCoverBitmap(Uri.decode(nextArtMrl), 512) : null;
                 WorkersKt.runOnMainThread(new Runnable() {
                     @Override
                     public void run() {



More information about the Android mailing list