feat: add technical stream info overlay for MPV player

This commit is contained in:
Fredrik Burmester
2026-01-12 09:05:15 +01:00
parent 3da4b42ca3
commit b0bb6c6c9a
14 changed files with 586 additions and 3 deletions

View File

@@ -430,6 +430,57 @@ class MPVLayerRenderer(private val context: Context) : MPVLib.EventObserver {
MPVLib.setPropertyDouble("panscan", panscanValue)
}
// MARK: - Technical Info
fun getTechnicalInfo(): Map<String, Any> {
val info = mutableMapOf<String, Any>()
// Video dimensions
MPVLib.getPropertyInt("video-params/w")?.takeIf { it > 0 }?.let {
info["videoWidth"] = it
}
MPVLib.getPropertyInt("video-params/h")?.takeIf { it > 0 }?.let {
info["videoHeight"] = it
}
// Video codec
MPVLib.getPropertyString("video-format")?.let {
info["videoCodec"] = it
}
// Audio codec
MPVLib.getPropertyString("audio-codec-name")?.let {
info["audioCodec"] = it
}
// FPS (container fps)
MPVLib.getPropertyDouble("container-fps")?.takeIf { it > 0 }?.let {
info["fps"] = it
}
// Video bitrate (bits per second)
MPVLib.getPropertyInt("video-bitrate")?.takeIf { it > 0 }?.let {
info["videoBitrate"] = it
}
// Audio bitrate (bits per second)
MPVLib.getPropertyInt("audio-bitrate")?.takeIf { it > 0 }?.let {
info["audioBitrate"] = it
}
// Demuxer cache duration (seconds of video buffered)
MPVLib.getPropertyDouble("demuxer-cache-duration")?.let {
info["cacheSeconds"] = it
}
// Dropped frames
MPVLib.getPropertyInt("frame-drop-count")?.let {
info["droppedFrames"] = it
}
return info
}
// MARK: - MPVLib.EventObserver
override fun eventProperty(property: String) {

View File

@@ -173,6 +173,11 @@ class MpvPlayerModule : Module() {
view.isZoomedToFill()
}
// Technical info function
AsyncFunction("getTechnicalInfo") { view: MpvPlayerView ->
view.getTechnicalInfo()
}
// Defines events that the view can send to JavaScript
Events("onLoad", "onPlaybackStateChange", "onProgress", "onError", "onTracksReady")
}

View File

@@ -330,6 +330,12 @@ class MpvPlayerView(context: Context, appContext: AppContext) : ExpoView(context
return _isZoomedToFill
}
// MARK: - Technical Info
fun getTechnicalInfo(): Map<String, Any> {
return renderer?.getTechnicalInfo() ?: emptyMap()
}
// MARK: - MPVLayerRenderer.Delegate
override fun onPositionChanged(position: Double, duration: Double) {