Fix loading indicator when playback ends

This commit is contained in:
Damontecres 2025-11-14 16:32:53 -05:00
parent e3efb2e500
commit 513302a1ed
No known key found for this signature in database
3 changed files with 51 additions and 2 deletions

View file

@ -253,14 +253,17 @@ fun PlaybackPage(
modifier = scaledModifier, modifier = scaledModifier,
) )
if (presentationState.coverSurface) { if (presentationState.coverSurface) {
val isLoading by rememberPlayerLoadingState(player)
Box( Box(
Modifier Modifier
.matchParentSize() .matchParentSize()
.background(Color.Black), .background(Color.Black),
) { ) {
if (isLoading) {
LoadingPage(focusEnabled = false) LoadingPage(focusEnabled = false)
} }
} }
}
// If D-pad skipping, show the amount skipped in an animation // If D-pad skipping, show the amount skipped in an animation
if (!controllerViewState.controlsVisible && skipIndicatorDuration != 0L) { if (!controllerViewState.controlsVisible && skipIndicatorDuration != 0L) {

View file

@ -0,0 +1,39 @@
package com.github.damontecres.wholphin.ui.playback
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.media3.common.Player
import androidx.media3.common.listen
import androidx.media3.common.util.UnstableApi
@UnstableApi
@Composable
fun rememberPlayerLoadingState(player: Player): PlayerLoadingState {
val state = remember(player) { PlayerLoadingState(player) }
LaunchedEffect(player) {
state.observe()
}
return state
}
@UnstableApi
class PlayerLoadingState(
private val player: Player,
) : State<Boolean> {
override var value by mutableStateOf(player.isLoading)
private set
suspend fun observe() {
value = player.isLoading
player.listen {
if (it.contains(Player.EVENT_IS_LOADING_CHANGED)) {
value = player.isLoading
}
}
}
}

View file

@ -89,6 +89,9 @@ class MpvPlayer(
var isReleased = false var isReleased = false
private set private set
@Volatile
private var isLoadingFile = false
init { init {
Timber.v("config-dir=${context.filesDir.path}") Timber.v("config-dir=${context.filesDir.path}")
MPVLib.create(context) MPVLib.create(context)
@ -260,7 +263,7 @@ class MpvPlayer(
override fun getShuffleModeEnabled(): Boolean = false override fun getShuffleModeEnabled(): Boolean = false
override fun isLoading(): Boolean = false override fun isLoading(): Boolean = isLoadingFile
override fun getSeekBackIncrement(): Long = 10_000 override fun getSeekBackIncrement(): Long = 10_000
@ -602,6 +605,8 @@ class MpvPlayer(
// MPV_EVENT_START_FILE -> { // MPV_EVENT_START_FILE -> {
// } // }
MPV_EVENT_FILE_LOADED -> { MPV_EVENT_FILE_LOADED -> {
isLoadingFile = false
notifyListeners(EVENT_IS_LOADING_CHANGED) { onIsLoadingChanged(false) }
Timber.d("event: MPV_EVENT_FILE_LOADED") Timber.d("event: MPV_EVENT_FILE_LOADED")
mediaItem!!.localConfiguration?.subtitleConfigurations?.forEach { mediaItem!!.localConfiguration?.subtitleConfigurations?.forEach {
val url = it.uri.toString() val url = it.uri.toString()
@ -685,6 +690,8 @@ class MpvPlayer(
} }
private fun loadFile() { private fun loadFile() {
isLoadingFile = true
notifyListeners(EVENT_IS_LOADING_CHANGED) { onIsLoadingChanged(true) }
val url = mediaItem!!.localConfiguration?.uri.toString() val url = mediaItem!!.localConfiguration?.uri.toString()
if (startPositionMs > 0) { if (startPositionMs > 0) {
MPVLib.command( MPVLib.command(