Fix double text subtitles by adding subfont

This commit is contained in:
Damontecres 2025-11-07 16:08:03 -05:00
parent 34dfd28011
commit b7a8cd3f92
No known key found for this signature in database
5 changed files with 50 additions and 11 deletions

View file

@ -0,0 +1,11 @@
{
"uniqueId": "com.github.mpv-android.mpv-android",
"developers": [],
"artifactVersion": "master",
"description": "mpv-android is a video player for Android based on libmpv",
"name": "mpv for Android",
"licenses": [
"mpv-android"
],
"website": "https://github.com/mpv-android/mpv-android"
}

View file

@ -0,0 +1,13 @@
{
"content": "Copyright (c) 2016 Ilya Zhuravlev
Copyright (c) 2016 sfan5 <sfan5@live.de>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"hash": "mpv-android",
"url": "https://github.com/mpv-android/mpv-android?tab=MIT-1-ov-file",
"name": "MIT"
}

Binary file not shown.

View file

@ -12,6 +12,7 @@ import com.github.damontecres.wholphin.preferences.updateInterfacePreferences
import com.github.damontecres.wholphin.preferences.updatePlaybackOverrides import com.github.damontecres.wholphin.preferences.updatePlaybackOverrides
import dagger.hilt.android.qualifiers.ApplicationContext import dagger.hilt.android.qualifiers.ApplicationContext
import timber.log.Timber import timber.log.Timber
import java.io.File
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -46,6 +47,7 @@ class AppUpgradeHandler
putLong(VERSION_CODE_CURRENT_KEY, newVersionCode) putLong(VERSION_CODE_CURRENT_KEY, newVersionCode)
} }
try { try {
copySubfont()
upgradeApp( upgradeApp(
context, context,
Version.fromString(previousVersion ?: "0.0.0"), Version.fromString(previousVersion ?: "0.0.0"),
@ -58,6 +60,20 @@ class AppUpgradeHandler
} }
} }
private fun copySubfont() {
try {
val fontFileName = "subfont.tff"
val outputFile = File(context.filesDir, fontFileName)
context.assets.open(fontFileName).use { input ->
outputFile.outputStream().use { output ->
input.copyTo(output)
}
}
} catch (ex: Exception) {
Timber.e(ex, "Exception copying subfont.tff")
}
}
companion object { companion object {
const val VERSION_NAME_PREVIOUS_KEY = "version.previous.name" const val VERSION_NAME_PREVIOUS_KEY = "version.previous.name"
const val VERSION_CODE_PREVIOUS_KEY = "version.previous.code" const val VERSION_CODE_PREVIOUS_KEY = "version.previous.code"

View file

@ -25,7 +25,6 @@ import androidx.media3.common.TrackGroup
import androidx.media3.common.TrackSelectionParameters import androidx.media3.common.TrackSelectionParameters
import androidx.media3.common.Tracks import androidx.media3.common.Tracks
import androidx.media3.common.VideoSize import androidx.media3.common.VideoSize
import androidx.media3.common.text.Cue
import androidx.media3.common.text.CueGroup import androidx.media3.common.text.CueGroup
import androidx.media3.common.util.Clock import androidx.media3.common.util.Clock
import androidx.media3.common.util.ListenerSet import androidx.media3.common.util.ListenerSet
@ -86,8 +85,11 @@ class MpvPlayer(
private set private set
init { init {
Timber.v("config-dir=${context.filesDir.path}")
MPVLib.create(context) MPVLib.create(context)
MPVLib.init() MPVLib.setOptionString("config", "yes")
MPVLib.setOptionString("config-dir", context.filesDir.path)
if (enableHardwareDecoding) { if (enableHardwareDecoding) {
MPVLib.setOptionString("hwdec", "mediacodec,mediacodec-copy") MPVLib.setOptionString("hwdec", "mediacodec,mediacodec-copy")
MPVLib.setOptionString("vo", "gpu") MPVLib.setOptionString("vo", "gpu")
@ -102,8 +104,11 @@ class MpvPlayer(
MPVLib.setOptionString("demuxer-max-bytes", "${cacheMegs * 1024 * 1024}") MPVLib.setOptionString("demuxer-max-bytes", "${cacheMegs * 1024 * 1024}")
MPVLib.setOptionString("demuxer-max-back-bytes", "${cacheMegs * 1024 * 1024}") MPVLib.setOptionString("demuxer-max-back-bytes", "${cacheMegs * 1024 * 1024}")
MPVLib.init()
MPVLib.setOptionString("force-window", "no") MPVLib.setOptionString("force-window", "no")
MPVLib.setOptionString("idle", "yes") MPVLib.setOptionString("idle", "yes")
MPVLib.addObserver(this) MPVLib.addObserver(this)
MPVProperty.observedProperties.forEach(MPVLib::observeProperty) MPVProperty.observedProperties.forEach(MPVLib::observeProperty)
@ -557,15 +562,6 @@ class MpvPlayer(
value: String, value: String,
) { ) {
if (DEBUG) Timber.v("eventPropertyString: $property=$value") if (DEBUG) Timber.v("eventPropertyString: $property=$value")
when (property) {
MPVProperty.SUBTITLE_TEXT -> {
if (DEBUG) Timber.v("Subtitles: $value")
val cues = listOf(Cue.Builder().setText(value).build())
// TODO need to deal with presentation time?
val cueGroup = CueGroup(cues, 10.seconds.inWholeMicroseconds)
notifyListeners(EVENT_CUES) { onCues(cueGroup) }
}
}
} }
override fun eventProperty( override fun eventProperty(
@ -598,6 +594,9 @@ class MpvPlayer(
MPV_EVENT_PLAYBACK_RESTART -> { MPV_EVENT_PLAYBACK_RESTART -> {
Timber.d("event: MPV_EVENT_PLAYBACK_RESTART") Timber.d("event: MPV_EVENT_PLAYBACK_RESTART")
getTracks().let {
notifyListeners(EVENT_TRACKS_CHANGED) { onTracksChanged(it) }
}
} }
MPV_EVENT_AUDIO_RECONFIG -> { MPV_EVENT_AUDIO_RECONFIG -> {