fix playing local anime source videos

This commit is contained in:
jmir1 2022-04-11 14:52:59 +02:00
parent e60bd4d07d
commit faa5e0b403

View file

@ -726,8 +726,7 @@ class PlayerActivity :
} }
subTracks = arrayOf(Track("nothing", "Off")) + it.subtitleTracks.toTypedArray() subTracks = arrayOf(Track("nothing", "Off")) + it.subtitleTracks.toTypedArray()
audioTracks = arrayOf(Track("nothing", "Off")) + it.audioTracks.toTypedArray() audioTracks = arrayOf(Track("nothing", "Off")) + it.audioTracks.toTypedArray()
val videoUrlString = resolveUri(Uri.parse(it.videoUrl)) MPVLib.command(arrayOf("loadfile", parseVideoUrl(it.videoUrl)))
MPVLib.command(arrayOf("loadfile", videoUrlString))
} }
launchUI { refreshUi() } launchUI { refreshUi() }
} }
@ -962,24 +961,18 @@ class PlayerActivity :
setViewMode() setViewMode()
subTracks = arrayOf(Track("nothing", "Off")) + it.subtitleTracks.toTypedArray() subTracks = arrayOf(Track("nothing", "Off")) + it.subtitleTracks.toTypedArray()
audioTracks = arrayOf(Track("nothing", "Off")) + it.audioTracks.toTypedArray() audioTracks = arrayOf(Track("nothing", "Off")) + it.audioTracks.toTypedArray()
val videoUrlString = resolveUri(Uri.parse(it.videoUrl)) MPVLib.command(arrayOf("loadfile", parseVideoUrl(it.videoUrl)))
MPVLib.command(arrayOf("loadfile", videoUrlString))
} }
launchUI { refreshUi() } launchUI { refreshUi() }
} }
private fun resolveUri(data: Uri): String { private fun parseVideoUrl(videoUrl: String?): String? {
val filepath = when (data.scheme) { val uri = Uri.parse(videoUrl)
"file" -> data.path return openContentFd(uri) ?: videoUrl
"content" -> openContentFd(data)
"http", "https", "rtmp", "rtmps", "rtp", "rtsp", "mms", "mmst", "mmsh", "tcp", "udp",
-> data.toString()
else -> null
}
return filepath ?: return ""
} }
private fun openContentFd(uri: Uri): String? { private fun openContentFd(uri: Uri): String? {
if (uri.scheme != "content") return null
val resolver = applicationContext.contentResolver val resolver = applicationContext.contentResolver
logcat { "Resolving content URI: $uri" } logcat { "Resolving content URI: $uri" }
val fd = try { val fd = try {