[Android] Catch DeviceRemovedException on media creation

Geoffrey Métais git at videolan.org
Wed Dec 5 11:29:55 CET 2018


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Dec  4 17:38:34 2018 +0100| [2cf0936b7c725a8a5540de26891e2ef4f4886c98] | committer: Geoffrey Métais

Catch DeviceRemovedException on media creation

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

 medialibrary/jni/utils.cpp | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index b300e7dae..e7c11f0bd 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -11,6 +11,7 @@
 #include <medialibrary/IFolder.h>
 #include <medialibrary/IMediaLibrary.h>
 #include <medialibrary/IMetadata.h>
+#include<medialibrary/filesystem/IDevice.h>
 #define LOG_TAG "VLC/JNI/Utils"
 #include "log.h"
 
@@ -62,7 +63,11 @@ mediaToMediaWrapper(JNIEnv* env, fields *fields, medialibrary::MediaPtr const& m
     jint  spuTrack = metaSpuTrack.isSet() ? metaSpuTrack.integer() : -2;
     title = mediaPtr->title().empty() ? NULL : env->NewStringUTF(mediaPtr->title().c_str());
     filename = mediaPtr->fileName().empty() ? NULL : env->NewStringUTF(mediaPtr->fileName().c_str());
-    mrl = env->NewStringUTF(files.at(0)->mrl().c_str());
+    try {
+        mrl = env->NewStringUTF(files.at(0)->mrl().c_str());
+    } catch(const medialibrary::fs::DeviceRemovedException&) {
+        return nullptr;
+    }
     thumbnail = mediaPtr->thumbnail().empty() ? NULL : env->NewStringUTF(mediaPtr->thumbnail().c_str());
     std::vector<medialibrary::VideoTrackPtr> videoTracks = mediaPtr->videoTracks()->all();
     bool hasVideoTracks = !videoTracks.empty();



More information about the Android mailing list