[Android] ExternalBrowser: avoid using fd if possible

Duncan McNamara git at videolan.org
Mon Jun 19 05:42:45 UTC 2023


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Tue Jun 13 17:49:21 2023 +0200| [c597ce85bc075f4c533b489796ef48a5011ea630] | committer: Duncan McNamara

ExternalBrowser: avoid using fd if possible

This is to use the media path directly if possible and avoid using the
fd forwarded to the app from an external browser. Using a fd means that
the app's permission to use the file will disappear which creates issues
when resuming media. Also, opening media from an fd means that the app
won't have access to any meta data.

Fixes #2496, #2861, #2862

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

 application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt b/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
index 70154abeb0..868874db54 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/FileUtils.kt
@@ -380,6 +380,9 @@ object FileUtils {
                 val media = medialibrary.getMedia(data.lastPathSegment!!.toLong())
                 uri = media.uri
             } else {
+                uri = MediaUtils.getContentMediaUri(data)
+                if (uri != null && uri != data)
+                    return uri
                 val inputPFD: ParcelFileDescriptor?
                 try {
                     inputPFD = ctx.contentResolver.openFileDescriptor(data, "r")



More information about the Android mailing list