[Android] medialibrary: Don't rely on isPresent before fetching the mrl
Hugo Beauzée-Luyssen
git at videolan.org
Wed May 6 13:37:41 CEST 2020
vlc-android | branch: master | Hugo Beauzée-Luyssen <hugo at beauzee.fr> | Tue May 5 11:50:04 2020 +0200| [08f26e193c509db94bcfca402a56c4cf2ca98b6e] | committer: Nicolas Pomepuy
medialibrary: Don't rely on isPresent before fetching the mrl
The device can still go away in between, so just catch the exception and
ignore missing devices
Fix medialibrary#245
> https://code.videolan.org/videolan/vlc-android/commit/08f26e193c509db94bcfca402a56c4cf2ca98b6e
---
medialibrary/jni/medialibrary.cpp | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/medialibrary/jni/medialibrary.cpp b/medialibrary/jni/medialibrary.cpp
index 252214749..cee754ac5 100644
--- a/medialibrary/jni/medialibrary.cpp
+++ b/medialibrary/jni/medialibrary.cpp
@@ -129,11 +129,21 @@ entryPoints(JNIEnv* env, jobject thiz)
{
AndroidMediaLibrary *aml = MediaLibrary_getInstance(env, thiz);
std::vector<medialibrary::FolderPtr> entryPoints = aml->entryPoints();
- entryPoints.erase(std::remove_if( begin( entryPoints ), end( entryPoints ), []( const medialibrary::FolderPtr f ) { return f->isPresent() == false; } ), end( entryPoints ));
- jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(entryPoints.size(), env->FindClass("java/lang/String"), NULL);
+ std::vector<std::string> mrls{ entryPoints.size() };
+ for(medialibrary::FolderPtr& entryPoint : entryPoints) {
+ try
+ {
+ mrls.push_back( std::move( entryPoint->mrl() ) );
+ }
+ catch ( const medialibrary::fs::errors::DeviceRemoved& )
+ {
+ // Just ignore, the device isn't available anymore
+ }
+ }
+ jobjectArray mediaRefs = (jobjectArray) env->NewObjectArray(mrls.size(), env->FindClass("java/lang/String"), NULL);
int index = -1;
- for(medialibrary::FolderPtr const& entrypoint : entryPoints) {
- jstring mrl = env->NewStringUTF(entrypoint->mrl().c_str());
+ for( const std::string& m : mrls ) {
+ jstring mrl = env->NewStringUTF(m.c_str());
env->SetObjectArrayElement(mediaRefs, ++index, mrl);
env->DeleteLocalRef(mrl);
}
More information about the Android
mailing list