[Android] Prevent NPE in playback service

Geoffrey Métais git at videolan.org
Fri Nov 3 15:42:25 CET 2017


vlc-android | branch: 2.5.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Nov  3 10:55:31 2017 +0100| [89373d5d3e534331d525cacbe95b5fa3a9ef75e8] | committer: Geoffrey Métais

Prevent NPE in playback service

(cherry picked from commit 8fcd6587506cfedc4fbd986d08e8d01fa6952107)

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

 .../src/org/videolan/vlc/PlaybackService.java        | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index 33cba0b88..e1d8961e0 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -1309,14 +1309,16 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                     } else if (vsp.isSongFocus) {
                         tracks = mMedialibrary.searchMedia(vsp.song).getTracks();
                     }
-                    if (Tools.isArrayEmpty(tracks)){
-                        SearchAggregate result = mMedialibrary.search(query);
-                        if (!Tools.isArrayEmpty(result.getAlbums()))
-                            tracks = result.getAlbums()[0].getTracks();
-                        else if (!Tools.isArrayEmpty(result.getArtists()))
-                            tracks = result.getArtists()[0].getTracks();
-                        else if (!Tools.isArrayEmpty(result.getGenres()))
-                            tracks = result.getGenres()[0].getTracks();
+                    if (Tools.isArrayEmpty(tracks)) {
+                        final SearchAggregate result = mMedialibrary.search(query);
+                        if (result != null) {
+                            if (!Tools.isArrayEmpty(result.getAlbums()))
+                                tracks = result.getAlbums()[0].getTracks();
+                            else if (!Tools.isArrayEmpty(result.getArtists()))
+                                tracks = result.getArtists()[0].getTracks();
+                            else if (!Tools.isArrayEmpty(result.getGenres()))
+                                tracks = result.getGenres()[0].getTracks();
+                        }
                     }
                     if (tracks == null && !Tools.isArrayEmpty(items))
                         tracks = items[0].getTracks();
@@ -1380,6 +1382,8 @@ public class PlaybackService extends MediaBrowserServiceCompat implements IVLCVo
                 synchronized (ExecutorHolder.updateMeta) {
                     ExecutorHolder.updateMeta.set(true);
                 }
+                if (media == null)
+                    return;
                 String title = media.getNowPlaying();
                 if (title == null)
                     title = media.getTitle();



More information about the Android mailing list