Fix mpv subfont.ttf not loading (#147)
This commit is contained in:
parent
c19350fa36
commit
9ce2950ea1
1 changed files with 12 additions and 13 deletions
|
@ -28,6 +28,7 @@ import kotlinx.parcelize.Parcelize
|
||||||
import org.json.JSONArray
|
import org.json.JSONArray
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
import timber.log.Timber
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.util.concurrent.CopyOnWriteArraySet
|
import java.util.concurrent.CopyOnWriteArraySet
|
||||||
|
@ -49,20 +50,18 @@ class MPVPlayer(
|
||||||
init {
|
init {
|
||||||
require(context is Application)
|
require(context is Application)
|
||||||
val mpvDir = File(context.getExternalFilesDir(null) ?: context.filesDir, "mpv")
|
val mpvDir = File(context.getExternalFilesDir(null) ?: context.filesDir, "mpv")
|
||||||
if (!mpvDir.exists()) {
|
Timber.i("mpv config dir: $mpvDir")
|
||||||
mpvDir.mkdirs()
|
if (!mpvDir.exists()) mpvDir.mkdirs()
|
||||||
}
|
|
||||||
arrayOf("mpv.conf", "subfont.ttf").forEach { fileName ->
|
arrayOf("mpv.conf", "subfont.ttf").forEach { fileName ->
|
||||||
val file = File(mpvDir, fileName)
|
val file = File(mpvDir, fileName)
|
||||||
Log.i("mpv", "File ${file.absolutePath}")
|
if (file.exists()) return@forEach
|
||||||
if (!file.exists()) {
|
context.assets.open(fileName, AssetManager.ACCESS_STREAMING)
|
||||||
context.assets.open(fileName, AssetManager.ACCESS_STREAMING)
|
.copyTo(FileOutputStream(file))
|
||||||
.copyTo(FileOutputStream(file))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
MPVLib.create(context)
|
MPVLib.create(context)
|
||||||
|
|
||||||
// General
|
// General
|
||||||
|
MPVLib.setOptionString("config", "yes")
|
||||||
MPVLib.setOptionString("config-dir", mpvDir.path)
|
MPVLib.setOptionString("config-dir", mpvDir.path)
|
||||||
MPVLib.setOptionString("vo", "gpu")
|
MPVLib.setOptionString("vo", "gpu")
|
||||||
MPVLib.setOptionString("gpu-context", "android")
|
MPVLib.setOptionString("gpu-context", "android")
|
||||||
|
@ -86,7 +85,7 @@ class MPVPlayer(
|
||||||
MPVLib.setOptionString("demuxer-max-back-bytes", "32MiB")
|
MPVLib.setOptionString("demuxer-max-back-bytes", "32MiB")
|
||||||
|
|
||||||
// Subs
|
// Subs
|
||||||
MPVLib.setOptionString("sub-scale-with-window", "no")
|
MPVLib.setOptionString("sub-scale-with-window", "yes")
|
||||||
MPVLib.setOptionString("sub-use-margins", "no")
|
MPVLib.setOptionString("sub-use-margins", "no")
|
||||||
|
|
||||||
// Other options
|
// Other options
|
||||||
|
@ -181,7 +180,7 @@ class MPVPlayer(
|
||||||
when (property) {
|
when (property) {
|
||||||
"track-list" -> {
|
"track-list" -> {
|
||||||
val (mpvTracks, newTracks) = getMPVTracks(value)
|
val (mpvTracks, newTracks) = getMPVTracks(value)
|
||||||
mpvTracks.forEach { Log.i("mpv", "${it.ffIndex} ${it.type} ${it.codec}") }
|
mpvTracks.forEach { Timber.i("${it.ffIndex} ${it.type} ${it.codec}") }
|
||||||
currentMpvTracks = mpvTracks
|
currentMpvTracks = mpvTracks
|
||||||
if (isPlayerReady) {
|
if (isPlayerReady) {
|
||||||
if (newTracks != tracks) {
|
if (newTracks != tracks) {
|
||||||
|
@ -300,7 +299,7 @@ class MPVPlayer(
|
||||||
}
|
}
|
||||||
seekTo(C.TIME_UNSET)
|
seekTo(C.TIME_UNSET)
|
||||||
if (playWhenReady) {
|
if (playWhenReady) {
|
||||||
Log.d("mpv", "Starting playback...")
|
Timber.d("Starting playback...")
|
||||||
MPVLib.setPropertyBoolean("pause", false)
|
MPVLib.setPropertyBoolean("pause", false)
|
||||||
}
|
}
|
||||||
for (videoListener in videoListeners) {
|
for (videoListener in videoListeners) {
|
||||||
|
@ -369,12 +368,12 @@ class MPVPlayer(
|
||||||
index: Int
|
index: Int
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (index != C.INDEX_UNSET) {
|
if (index != C.INDEX_UNSET) {
|
||||||
Log.i("mpv", "${currentMpvTracks.size}")
|
Timber.i("${currentMpvTracks.size}")
|
||||||
currentMpvTracks.firstOrNull {
|
currentMpvTracks.firstOrNull {
|
||||||
it.type == trackType && (if (isExternal) it.title else "${it.ffIndex}") == "$index"
|
it.type == trackType && (if (isExternal) it.title else "${it.ffIndex}") == "$index"
|
||||||
}.let { track ->
|
}.let { track ->
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
Log.i("mpv", "selected track ${track.ffIndex} ${track.type}")
|
Timber.i("selected track ${track.ffIndex} ${track.type}")
|
||||||
if (!track.selected) {
|
if (!track.selected) {
|
||||||
MPVLib.setPropertyInt(trackType, track.id)
|
MPVLib.setPropertyInt(trackType, track.id)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue