Fix some build issues

This commit is contained in:
Damontecres 2025-11-05 14:08:50 -05:00
parent 1ee834d42b
commit 85a32d18d3
No known key found for this signature in database
4 changed files with 110 additions and 35 deletions

View file

@ -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,
)
}

View file

@ -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<Player.Listener>()
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")
}
}