From 85a32d18d320b993b859fd7c2f3186165914ac5b Mon Sep 17 00:00:00 2001 From: Damontecres Date: Wed, 5 Nov 2025 14:08:50 -0500 Subject: [PATCH] Fix some build issues --- app/build.gradle.kts | 45 +++++--------- .../wholphin/util/mpv/MPVProperty.kt | 40 +++++++++++++ .../wholphin/util/mpv/MpvPlayer.kt | 58 ++++++++++++++++++- scripts/mpv/get_dependencies.sh | 2 + 4 files changed, 110 insertions(+), 35 deletions(-) create mode 100644 app/src/main/java/com/github/damontecres/wholphin/util/mpv/MPVProperty.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index c8c88f34..d9b47b8f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -134,25 +134,24 @@ android { } } -// applicationVariants.all { -// val variant = this -// variant.outputs -// .map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl } -// .forEach { output -> -// val outputFileName = -// "Wholphin-${variant.baseName}-${variant.versionName}-${variant.versionCode}.apk" -// output.outputFileName = outputFileName -// } -// } + applicationVariants.all { + val variant = this + variant.outputs + .map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl } + .forEach { output -> + val outputFileName = + "Wholphin-${variant.baseName}-${variant.versionName}-${variant.versionCode}.apk" + output.outputFileName = outputFileName + } + } } splits { abi { - isEnable = true + isEnable = false reset() - include("arm64-v8a") -// include("armeabi-v7a") // TODO - isUniversalApk = false +// include("armeabi-v7a", "arm64-v8a") + isUniversalApk = true } } } @@ -186,24 +185,6 @@ aboutLibraries { } } -// Map versionCode so each ABI gets a different one -// e.g. x86 with version 21 gets a versionCode of 3021 -// val abiCodes = mapOf("armeabi-v7a" to 1, "arm64-v8a" to 2, "x86" to 3, "x86_64" to 4) -// val universalBase = 8000 -// android.applicationVariants.all { variant -> -// variant.outputs.forEach { output -> -// val base = output.filters.firstOrNull { it.filterType==VariantOutput.ABI } -// // val base = abiCodes.get(output.getFilter(VariantOutput.ABI)) -// // universal APK just gets a constant added to it -// if (base != null) { -// output.versionCodeOverride = base * 1000 + variant.versionCode -// } else { -// output.versionCodeOverride = universalBase + variant.versionCode -// } -// } -// true -// } - dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) diff --git a/app/src/main/java/com/github/damontecres/wholphin/util/mpv/MPVProperty.kt b/app/src/main/java/com/github/damontecres/wholphin/util/mpv/MPVProperty.kt new file mode 100644 index 00000000..2ff01c86 --- /dev/null +++ b/app/src/main/java/com/github/damontecres/wholphin/util/mpv/MPVProperty.kt @@ -0,0 +1,40 @@ +package com.github.damontecres.wholphin.util.mpv + +import com.github.damontecres.wholphin.util.mpv.MPVLib.MpvFormat.MPV_FORMAT_DOUBLE +import com.github.damontecres.wholphin.util.mpv.MPVLib.MpvFormat.MPV_FORMAT_FLAG +import com.github.damontecres.wholphin.util.mpv.MPVLib.MpvFormat.MPV_FORMAT_INT64 +import com.github.damontecres.wholphin.util.mpv.MPVLib.MpvFormat.MPV_FORMAT_NONE +import com.github.damontecres.wholphin.util.mpv.MPVLib.MpvFormat.MPV_FORMAT_STRING + +object MPVProperty { + const val POSITION = "time-pos" + const val DURATION = "duration/full" + const val PAUSED = "pause" + const val PAUSED_FOR_CACHE = "paused-for-cache" + const val SPEED = "speed" + const val TRACK_LIST = "track-list" + const val ASPECT = "video-params/aspect" + const val ROTATE = "video-params/rotate" + const val TRACK_VIDEO = "current-tracks/video/image" + const val METADATA = "metadata" + const val HWDEC = "hwdec-current" + const val MUTE = "mute" + const val TRACK_AUDIO = "current-tracks/audio/selected" + + val observedProperties = + mapOf( + POSITION to MPV_FORMAT_INT64, + DURATION to MPV_FORMAT_DOUBLE, + PAUSED to MPV_FORMAT_FLAG, + PAUSED_FOR_CACHE to MPV_FORMAT_FLAG, + SPEED to MPV_FORMAT_STRING, + TRACK_LIST to MPV_FORMAT_NONE, + ASPECT to MPV_FORMAT_DOUBLE, + ROTATE to MPV_FORMAT_DOUBLE, + TRACK_VIDEO to MPV_FORMAT_NONE, + METADATA to MPV_FORMAT_NONE, + HWDEC to MPV_FORMAT_NONE, + MUTE to MPV_FORMAT_FLAG, + TRACK_AUDIO to MPV_FORMAT_NONE, + ) +} 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 73d5bcf4..53d5a06f 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,12 +25,16 @@ import androidx.media3.common.text.CueGroup import androidx.media3.common.util.Size import androidx.media3.common.util.UnstableApi import androidx.media3.common.util.Util +import timber.log.Timber +import kotlin.concurrent.atomics.ExperimentalAtomicApi import kotlin.time.Duration.Companion.milliseconds +@kotlin.OptIn(ExperimentalAtomicApi::class) @OptIn(UnstableApi::class) class MpvPlayer( private val context: Context, -) : BasePlayer() { +) : BasePlayer(), + MPVLib.EventObserver { private var surface: Surface? = null private val listeners = mutableListOf() private val looper = Util.getCurrentOrMainLooper() @@ -42,8 +46,13 @@ class MpvPlayer( init { MPVLib.create(context) MPVLib.init() - MPVLib.setOptionString("hwdec", "mediacodec,mediacodec-copy") + // TODO add option for enabling HW decoding +// MPVLib.setOptionString("hwdec", "mediacodec,mediacodec-copy") +// MPVLib.setOptionString("vo", "gpu") MPVLib.setOptionString("gpu-context", "android") + // TODO disable HW decoding for now + MPVLib.setOptionString("hwdec", "no") + MPVLib.setOptionString("opengl-es", "yes") MPVLib.setOptionString("hwdec-codecs", "h264,hevc,mpeg4,mpeg2video,vp8,vp9,av1") val cacheMegs = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) 64 else 32 @@ -53,6 +62,8 @@ class MpvPlayer( MPVLib.setOptionString("force-window", "no") // need to idle at least once for playFile() logic to work MPVLib.setOptionString("idle", "once") + MPVLib.addObserver(this) + MPVProperty.observedProperties.forEach(MPVLib::observeProperty) availableCommands = Player.Commands @@ -228,7 +239,7 @@ class MpvPlayer( override fun getCurrentMediaItemIndex(): Int = 0 override fun getDuration(): Long { - val duration = MPVLib.getPropertyDouble("duration")!!.milliseconds.inWholeMilliseconds + val duration = MPVLib.getPropertyDouble("duration/full")!!.milliseconds.inWholeMilliseconds return duration } @@ -279,17 +290,22 @@ class MpvPlayer( this.surfaceSize = if (surface == null) Size(0, 0) else Size.UNKNOWN if (surface != null) { this.surface = surface + Timber.v("Queued attach") MPVLib.attachSurface(surface) MPVLib.setOptionString("force-window", "yes") + Timber.d("Attached surface") val url = mediaItem!!.localConfiguration?.uri.toString() MPVLib.command(arrayOf("loadfile", url)) + MPVLib.setPropertyString("vo", "gpu") + Timber.d("Called loadfile") } else { clearVideoSurfaceView(null) } } override fun clearVideoSurfaceView(surfaceView: SurfaceView?) { + Timber.d("Detaching surface") MPVLib.detachSurface() MPVLib.setPropertyString("vo", "null") MPVLib.setPropertyString("force-window", "no") @@ -389,4 +405,40 @@ class MpvPlayer( } MPVLib.setPropertyDouble("time-pos", positionMs.toDouble()) } + + override fun eventProperty(property: String) { + Timber.v("eventProperty: $property") + } + + override fun eventProperty( + property: String, + value: Long, + ) { + Timber.v("eventProperty: $property=$value") + } + + override fun eventProperty( + property: String, + value: Boolean, + ) { + Timber.v("eventProperty: $property=$value") + } + + override fun eventProperty( + property: String, + value: String, + ) { + Timber.v("eventProperty: $property=$value") + } + + override fun eventProperty( + property: String, + value: Double, + ) { + Timber.v("eventProperty: $property=$value") + } + + override fun event(eventId: Int) { + Timber.v("event: $eventId") + } } diff --git a/scripts/mpv/get_dependencies.sh b/scripts/mpv/get_dependencies.sh index b892288f..f94c5c8e 100755 --- a/scripts/mpv/get_dependencies.sh +++ b/scripts/mpv/get_dependencies.sh @@ -66,3 +66,5 @@ if [[ ! -d lua ]]; then fi # python packages: jsonschema jinja2 meson + +popd || exit