[Android] Create MediaWrapper even if ML is not able to retrieve a mrl

Nicolas Pomepuy git at videolan.org
Thu Feb 3 09:23:57 UTC 2022


vlc-android | branch: 3.4.x | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Dec 16 09:36:49 2021 +0100| [5bcc411a8b66bf3ff6d162069fe355972e75e5d5] | committer: Nicolas Pomepuy

Create MediaWrapper even if ML is not able to retrieve a mrl

Fixes #2273


(cherry picked from commit 242f8b393b401f742356e5b98d922359ab5ead8a)

> https://code.videolan.org/videolan/vlc-android/commit/5bcc411a8b66bf3ff6d162069fe355972e75e5d5
---

 application/resources/src/main/res/values/strings.xml              | 1 +
 .../vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt      | 7 +++++--
 medialibrary/jni/utils.cpp                                         | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index a78daf499..4420adee2 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -202,6 +202,7 @@
     <string name="encountered_error_title">Playback error</string>
     <string name="encountered_error_message">VLC encountered an error with this media.\nPlease try refreshing the media library.</string>
     <string name="invalid_location">The location %1$s cannot be played.</string>
+    <string name="missing_location">This media is from a unavailable storage and cannot be played.</string>
 
     <string name="search">Search</string>
 
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 ce8d5291c..2312d346e 100644
--- a/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
+++ b/application/vlc-android/src/org/videolan/vlc/media/PlaylistManager.kt
@@ -1,6 +1,7 @@
 package org.videolan.vlc.media
 
 import android.content.Intent
+import android.net.Uri
 import android.support.v4.media.session.PlaybackStateCompat
 import android.util.Log
 import android.widget.Toast
@@ -122,7 +123,7 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                     if (mediaWrapper === null) {
                         if (!location.validateLocation()) {
                             Log.w(TAG, "Invalid location $location")
-                            service.showToast(service.resources.getString(R.string.invalid_location, location), Toast.LENGTH_SHORT)
+                            service.showToast(if (Uri.parse(location).scheme == "missing")service.resources.getString(R.string.missing_location) else service.resources.getString(R.string.invalid_location,  location), Toast.LENGTH_SHORT)
                             continue
                         }
                         Log.v(TAG, "Creating on-the-fly Media object for $location")
@@ -961,7 +962,9 @@ class PlaylistManager(val service: PlaybackService) : MediaWrapperList.EventList
                     }
                 }
                 MediaPlayer.Event.EncounteredError -> {
-                    service.showToast(service.getString(
+                    Log.w(TAG, "Invalid location ${getCurrentMedia()?.location}")
+
+                    service.showToast(if (Uri.parse(getCurrentMedia()?.location).scheme == "missing") service.getString(R.string.missing_location) else service.getString(
                             R.string.invalid_location,
                             getCurrentMedia()?.location ?: ""), Toast.LENGTH_SHORT, true)
                     if (currentIndex != nextIndex) next() else stop()
diff --git a/medialibrary/jni/utils.cpp b/medialibrary/jni/utils.cpp
index 151b218a2..4d4c5be8c 100644
--- a/medialibrary/jni/utils.cpp
+++ b/medialibrary/jni/utils.cpp
@@ -58,7 +58,7 @@ mediaToMediaWrapper(JNIEnv* env, fields *fields, medialibrary::MediaPtr const& m
     try {
         mrl = vlcNewStringUTF(env, files.at(0)->mrl().c_str());
     } catch(const medialibrary::fs::errors::DeviceRemoved&) {
-        return {};
+        mrl = vlcNewStringUTF(env, "missing://");
     }
     auto thumbnailStr = mediaPtr->thumbnailMrl(medialibrary::ThumbnailSizeType::Thumbnail);
     if (!thumbnailStr.empty())



More information about the Android mailing list