diff --git a/app/config/libraries/lib_mpv_android.json b/app/config/libraries/lib_mpv_android.json new file mode 100644 index 00000000..5074eb61 --- /dev/null +++ b/app/config/libraries/lib_mpv_android.json @@ -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" +} diff --git a/app/config/licenses/lic_mpv_android.json b/app/config/licenses/lic_mpv_android.json new file mode 100644 index 00000000..9dd7f9fe --- /dev/null +++ b/app/config/licenses/lic_mpv_android.json @@ -0,0 +1,13 @@ +{ + "content": "Copyright (c) 2016 Ilya Zhuravlev +Copyright (c) 2016 sfan5 + +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" +} diff --git a/app/src/main/assets/subfont.ttf b/app/src/main/assets/subfont.ttf new file mode 100644 index 00000000..9659afc6 Binary files /dev/null and b/app/src/main/assets/subfont.ttf differ diff --git a/app/src/main/java/com/github/damontecres/wholphin/util/AppUpgradeHandler.kt b/app/src/main/java/com/github/damontecres/wholphin/util/AppUpgradeHandler.kt index b010750c..1615c60b 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/util/AppUpgradeHandler.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/util/AppUpgradeHandler.kt @@ -12,6 +12,7 @@ import com.github.damontecres.wholphin.preferences.updateInterfacePreferences import com.github.damontecres.wholphin.preferences.updatePlaybackOverrides import dagger.hilt.android.qualifiers.ApplicationContext import timber.log.Timber +import java.io.File import javax.inject.Inject import javax.inject.Singleton @@ -46,6 +47,7 @@ class AppUpgradeHandler putLong(VERSION_CODE_CURRENT_KEY, newVersionCode) } try { + copySubfont() upgradeApp( context, 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 { const val VERSION_NAME_PREVIOUS_KEY = "version.previous.name" const val VERSION_CODE_PREVIOUS_KEY = "version.previous.code" diff --git a/app/src/main/java/com/github/damontecres/wholphin/util/mpv/MpvPlayer.kt b/app/src/main/java/com/github/damontecres/wholphin/util/mpv/MpvPlayer.kt index 9f1f738d..06e81df4 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/util/mpv/MpvPlayer.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/util/mpv/MpvPlayer.kt @@ -25,7 +25,6 @@ import androidx.media3.common.TrackGroup import androidx.media3.common.TrackSelectionParameters import androidx.media3.common.Tracks import androidx.media3.common.VideoSize -import androidx.media3.common.text.Cue import androidx.media3.common.text.CueGroup import androidx.media3.common.util.Clock import androidx.media3.common.util.ListenerSet @@ -86,8 +85,11 @@ class MpvPlayer( private set init { + Timber.v("config-dir=${context.filesDir.path}") MPVLib.create(context) - MPVLib.init() + MPVLib.setOptionString("config", "yes") + MPVLib.setOptionString("config-dir", context.filesDir.path) + if (enableHardwareDecoding) { MPVLib.setOptionString("hwdec", "mediacodec,mediacodec-copy") MPVLib.setOptionString("vo", "gpu") @@ -102,8 +104,11 @@ class MpvPlayer( MPVLib.setOptionString("demuxer-max-bytes", "${cacheMegs * 1024 * 1024}") MPVLib.setOptionString("demuxer-max-back-bytes", "${cacheMegs * 1024 * 1024}") + MPVLib.init() + MPVLib.setOptionString("force-window", "no") MPVLib.setOptionString("idle", "yes") + MPVLib.addObserver(this) MPVProperty.observedProperties.forEach(MPVLib::observeProperty) @@ -557,15 +562,6 @@ class MpvPlayer( value: String, ) { 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( @@ -598,6 +594,9 @@ class MpvPlayer( MPV_EVENT_PLAYBACK_RESTART -> { Timber.d("event: MPV_EVENT_PLAYBACK_RESTART") + getTracks().let { + notifyListeners(EVENT_TRACKS_CHANGED) { onTracksChanged(it) } + } } MPV_EVENT_AUDIO_RECONFIG -> {