mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-08-17 12:57:03 +00:00
parent
d6a0d2da52
commit
749917bcd7
1 changed files with 28 additions and 14 deletions
|
|
@ -823,6 +823,12 @@ private fun LibmpvPlayerSurface(
|
|||
}
|
||||
override fun event(eventId: Int, data: MPVNode) {
|
||||
when (eventId) {
|
||||
MPV.mpvEvent.MPV_EVENT_START_FILE -> {
|
||||
coroutineScope.launch(Dispatchers.Main.immediate) {
|
||||
latestOnError.value(null)
|
||||
latestOnSnapshot.value(PlayerPlaybackSnapshot())
|
||||
}
|
||||
}
|
||||
MPV.mpvEvent.MPV_EVENT_FILE_LOADED,
|
||||
MPV.mpvEvent.MPV_EVENT_PLAYBACK_RESTART -> {
|
||||
coroutineScope.launch(Dispatchers.Main.immediate) {
|
||||
|
|
@ -853,6 +859,7 @@ private fun LibmpvPlayerSurface(
|
|||
|
||||
LaunchedEffect(playerViewRef, sourceUrl, sourceAudioUrl, sanitizedSourceHeaders, externalSubtitles) {
|
||||
val view = playerViewRef ?: return@LaunchedEffect
|
||||
latestOnSnapshot.value(PlayerPlaybackSnapshot())
|
||||
view.loadSource(
|
||||
sourceUrl = sourceUrl,
|
||||
sourceAudioUrl = sourceAudioUrl,
|
||||
|
|
@ -860,7 +867,6 @@ private fun LibmpvPlayerSurface(
|
|||
externalSubtitles = externalSubtitles,
|
||||
playWhenReady = latestPlayWhenReady.value,
|
||||
)
|
||||
latestOnSnapshot.value(view.snapshot())
|
||||
}
|
||||
|
||||
LaunchedEffect(playerViewRef, playWhenReady) {
|
||||
|
|
@ -874,7 +880,7 @@ private fun LibmpvPlayerSurface(
|
|||
playerViewRef?.applyResizeMode(resizeMode)
|
||||
}
|
||||
|
||||
LaunchedEffect(playerViewRef) {
|
||||
LaunchedEffect(playerViewRef, sourceUrl, sourceAudioUrl, sanitizedSourceHeaders, externalSubtitles) {
|
||||
val view = playerViewRef ?: return@LaunchedEffect
|
||||
onControllerReady(view.controller(context))
|
||||
}
|
||||
|
|
@ -992,20 +998,29 @@ private class NuvioLibmpvView(
|
|||
currentSourceAudioUrl = sourceAudioUrl
|
||||
currentRequestHeaders = requestHeaders
|
||||
currentExternalSubtitles = externalSubtitles
|
||||
applyRequestHeaders(requestHeaders)
|
||||
setPaused(!playWhenReady)
|
||||
if (!sameSource) {
|
||||
playFile(sourceUrl)
|
||||
if (!sourceAudioUrl.isNullOrBlank()) {
|
||||
mpv.command("audio-add", sourceAudioUrl, "auto")
|
||||
}
|
||||
externalSubtitles.forEachIndexed { index, subtitle ->
|
||||
val flag = if (index == 0) "auto" else "cached"
|
||||
mpv.command("sub-add", subtitle.url, flag)
|
||||
}
|
||||
loadCurrentSource(playWhenReady = playWhenReady)
|
||||
} else {
|
||||
applyRequestHeaders(requestHeaders)
|
||||
setPaused(!playWhenReady)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadCurrentSource(playWhenReady: Boolean) {
|
||||
val sourceUrl = currentSourceUrl ?: return
|
||||
applyRequestHeaders(currentRequestHeaders)
|
||||
setPaused(!playWhenReady)
|
||||
mpv.command("loadfile", sourceUrl, "replace")
|
||||
currentSourceAudioUrl?.takeIf { it.isNotBlank() }?.let { sourceAudioUrl ->
|
||||
mpv.command("audio-add", sourceAudioUrl, "auto")
|
||||
}
|
||||
currentExternalSubtitles.forEachIndexed { index, subtitle ->
|
||||
val flag = if (index == 0) "auto" else "cached"
|
||||
mpv.command("sub-add", subtitle.url, flag)
|
||||
}
|
||||
setPaused(!playWhenReady)
|
||||
}
|
||||
|
||||
fun setPaused(paused: Boolean) {
|
||||
runCatching { mpv.setPropertyBoolean("pause", paused) }
|
||||
}
|
||||
|
|
@ -1071,8 +1086,7 @@ private class NuvioLibmpvView(
|
|||
}
|
||||
|
||||
override fun retry() {
|
||||
currentSourceUrl?.let { playFile(it) }
|
||||
setPaused(false)
|
||||
loadCurrentSource(playWhenReady = true)
|
||||
}
|
||||
|
||||
override fun setPlaybackSpeed(speed: Float) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue