[Android] Prevent NPE on resumption of media session

Robert Stone git at videolan.org
Tue May 18 05:28:09 UTC 2021


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Mon May 17 21:39:11 2021 -0700| [29602b4e7425d48b1843d76b77c753310a0eba84] | committer: Robert Stone

Prevent NPE on resumption of media session

Fixes #1434

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

 .../src/org/videolan/vlc/media/PlaylistManager.kt          | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
index d3d41a7e9..86aa4b60e 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -903,16 +903,20 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
             var id = mw.id
             if (id == 0L) {
                 var internalMedia = medialibrary.findMedia(mw)
-                if (internalMedia != null && internalMedia.id != 0L)
+                if (internalMedia != null && internalMedia.id != 0L) {
                     id = internalMedia.id
-                else {
+                } else {
                     internalMedia = if (mw.type == MediaWrapper.TYPE_STREAM) {
                         medialibrary.addStream(entryUrl ?: mw.uri.toString(), mw.title).also {
                             entryUrl = null
                         }
-                    } else medialibrary.addMedia(mw.uri.toString(), mw.length)
-                    getCurrentMedia()?.let {currentMedia -> if (internalMedia.title != currentMedia.title) internalMedia.rename(currentMedia.title) }
-                    if (internalMedia != null) id = internalMedia.id
+                    } else {
+                        medialibrary.addMedia(mw.uri.toString(), mw.length)
+                    }
+                    if (internalMedia != null) {
+                        id = internalMedia.id
+                        getCurrentMedia()?.let { currentMedia -> if (internalMedia.title != currentMedia.title) internalMedia.rename(currentMedia.title) }
+                    }
                 }
             }
             if (id != 0L) medialibrary.setProgress(id, 1.0f)



More information about the Android mailing list