From da2145459e2db027f336e2ee7d25b2465d0ffc89 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 18 May 2026 01:40:00 +0000 Subject: [PATCH] fix: normalize video/x-m4v to video/mp4 when saving to MediaStore Android's MediaStore rejects video/x-m4v (returned by MimeTypeMap for .m4v URLs) with IllegalArgumentException. M4V is an MP4 container variant, so map it to video/mp4 before the ContentResolver.insert call. --- .../amethyst/ui/actions/MediaSaverToDisk.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/MediaSaverToDisk.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/MediaSaverToDisk.kt index 9837d17e2d..5a96931fef 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/MediaSaverToDisk.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/actions/MediaSaverToDisk.kt @@ -205,7 +205,7 @@ object MediaSaverToDisk { contentSource: BufferedSource, contentResolver: ContentResolver, ) { - val cleanMimeType = contentType.substringBefore(";").trim() + val cleanMimeType = normalizeMimeTypeForMediaStore(contentType.substringBefore(";").trim()) val (masterUri, baseDir) = when { @@ -271,6 +271,15 @@ object MediaSaverToDisk { private fun trimInlineMetaData(url: String): String = url.substringBefore("#") + // Android's MediaStore only accepts a fixed allow-list of MIME types. + // MimeTypeMap returns variants like video/x-m4v that MediaProvider rejects, + // so map them to the closest supported equivalent. + private fun normalizeMimeTypeForMediaStore(mimeType: String): String = + when (mimeType.lowercase()) { + "video/x-m4v" -> "video/mp4" + else -> mimeType + } + private const val AMETHYST_SUBDIRECTORY = "Amethyst" private const val PDF_MIME_TYPE = "application/pdf" }