[Android] Playlist creation can fail

Geoffrey Métais git at videolan.org
Mon Apr 10 17:32:32 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Apr 10 17:28:50 2017 +0200| [3cfbe5d2c5973fda62bcf5c6f52eae257b6a8631] | committer: Geoffrey Métais

Playlist creation can fail

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

 medialibrary/jni/medialibrary.cpp                                   | 6 ++----
 .../src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java        | 2 ++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index e99f6d2..1e78a56 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -496,9 +496,7 @@ getPlaylist(JNIEnv* env, jobject thiz, jlong id)
 {
     AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
     medialibrary::PlaylistPtr playlist = aml->playlist(id);
-    if (playlist != nullptr)
-        return convertPlaylistObject(env, &ml_fields, playlist);
-    return nullptr;
+    return playlist != nullptr ? convertPlaylistObject(env, &ml_fields, playlist) : nullptr;
 }
 
 jobject
@@ -508,7 +506,7 @@ playlistCreate(JNIEnv* env, jobject thiz, jstring name)
     const char *name_cstr = env->GetStringUTFChars(name, JNI_FALSE);
     medialibrary::PlaylistPtr playlist = aml->PlaylistCreate(name_cstr);
     env->ReleaseStringUTFChars(name, name_cstr);
-    return convertPlaylistObject(env, &ml_fields, playlist);
+    return playlist != nullptr ? convertPlaylistObject(env, &ml_fields, playlist) : nullptr;
 }
 
 /*
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
index 73fa15b..814a7fc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/SavePlaylistDialog.java
@@ -148,6 +148,8 @@ public class SavePlaylistDialog extends DialogFragment implements View.OnClickLi
                 MediaWrapper[] tracks;
                 if (!exists)
                     playlist = mMedialibrary.createPlaylist(name);
+                if (playlist == null)
+                    return;
                 if (addTracks) {
                     tracks = mNewTrack;
                 } else {//Save a playlist



More information about the Android mailing list