mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Fix double text subtitles by adding subfont
This commit is contained in:
parent
34dfd28011
commit
b7a8cd3f92
5 changed files with 50 additions and 11 deletions
11
app/config/libraries/lib_mpv_android.json
Normal file
11
app/config/libraries/lib_mpv_android.json
Normal 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"
|
||||||
|
}
|
||||||
13
app/config/licenses/lic_mpv_android.json
Normal file
13
app/config/licenses/lic_mpv_android.json
Normal 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"
|
||||||
|
}
|
||||||
BIN
app/src/main/assets/subfont.ttf
Normal file
BIN
app/src/main/assets/subfont.ttf
Normal file
Binary file not shown.
|
|
@ -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"
|
||||||
|
|
|
||||||
|
|
@ -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 -> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue