mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-08 23:54:39 +00:00
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.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user