mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-09 08:01:20 +02:00
Fix loading indicator when playback ends
This commit is contained in:
parent
e3efb2e500
commit
513302a1ed
3 changed files with 51 additions and 2 deletions
|
|
@ -253,12 +253,15 @@ 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),
|
||||||
) {
|
) {
|
||||||
LoadingPage(focusEnabled = false)
|
if (isLoading) {
|
||||||
|
LoadingPage(focusEnabled = false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue