[Android] StartActivity: fix shared video without mime

Duncan McNamara git at videolan.org
Tue Jul 7 13:03:53 UTC 2026


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Tue Jun  9 16:15:00 2026 +0200| [782ca7bdc9e2c4ad195b51d78bc4de5305ec1c5a] | committer: Nicolas Pomepuy

StartActivity: fix shared video without mime

Some browsers don't share files with a mime type, and it seems that
openMediaNoUi doesn't reopen the proper video but the previously
playing one. Forcing the video player in that case fixes the issue.

Basically there is a race condition between openMediaNoUi and the
VideoPlayerActivity opening where it replaces the new media with the old
one. I haven't managed to fix it yet.

This commit has the advantage of very limited side effects while we wait
to tackle the VideoPlayerActivity / PlaylistManager loading problems

Fixes #3302

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

 .../src/org/videolan/vlc/StartActivity.kt          | 32 ++++++++++++++++++----
 1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
index 526614f7fb..5410f79f01 100644
--- a/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/StartActivity.kt
@@ -59,6 +59,7 @@ import org.videolan.resources.TV_ONBOARDING_ACTIVITY
 import org.videolan.resources.TV_SEARCH_ACTIVITY
 import org.videolan.resources.util.getFromMl
 import org.videolan.resources.util.launchForeground
+import org.videolan.resources.util.parcelable
 import org.videolan.resources.util.startMedialibrary
 import org.videolan.tools.AppScope
 import org.videolan.tools.BETA_WELCOME
@@ -157,20 +158,41 @@ class StartActivity : FragmentActivity() {
         } else if (Intent.ACTION_SEND == action) {
             val cd = intent.clipData
             val item = if (cd != null && cd.itemCount > 0) cd.getItemAt(0) else null
-            if (item != null) {
-                var uri: Uri? = FileUtils.getUri(item.uri)
-                if (uri == null && item.text != null) uri = item.text.toString().toUri()
-                if (uri != null) {
+            val rawUri: Uri? = item?.uri ?: intent.parcelable<Uri>(Intent.EXTRA_STREAM)
+            if (rawUri != null) {
+                // try to get a mime type, amaze doesn't seem to share a video with it
+                val mimeType: String? = intent.type
+                    ?.takeIf { it.startsWith("video") || it.startsWith("audio") }
+                    ?: runCatching { contentResolver.getType(rawUri) }.getOrNull()
+                // If we have a video mime, we can force the video player
+                if (mimeType?.startsWith("video") == true) {
+                    startPlaybackFromApp(Intent(Intent.ACTION_VIEW, rawUri).apply {
+                        setDataAndType(rawUri, mimeType)
+                    })
+                } else {
                     lifecycleScope.launch {
+                        val uri = withContext(Dispatchers.IO) { FileUtils.getUri(rawUri) } ?: rawUri
                         var media = getFromMl { getMedia(uri) }
                         if (media == null)
                             media = MLServiceLocator.getAbstractMediaWrapper(uri)
                         MediaUtils.openMediaNoUi(this at StartActivity, media)
                         finish()
                     }
-                    return
                 }
+                return
+            } else if (item?.text != null) {
+                val textUri = item.text.toString().toUri()
+                lifecycleScope.launch {
+                    var media = getFromMl { getMedia(textUri) }
+                    if (media == null)
+                        media = MLServiceLocator.getAbstractMediaWrapper(textUri)
+                    MediaUtils.openMediaNoUi(this at StartActivity, media)
+                    finish()
+                }
+                return
             }
+            finish()
+            return
         }
 
         // Setting test mode with stubbed media library if required



More information about the Android mailing list