mirror of
https://github.com/narrrl/proton-stream.git
synced 2026-11-03 16:41:26 +01:00
perf(android,ios): warm what an episode opens with, and the next one near the end
The bridge's open_stream started no fetch until mpv asked, so every open was the head and then the tail, one after the other. It now warms both edges as the desktop does, and the resume block too when the episode resumes. warm_episode fetches another episode's opening blocks into the cache without playing it. Both phones call it for the next episode in the last two minutes or once the credits start, as the desktop already did, so autoplay starts from the cache.
This commit is contained in:
1 parent
8d795c29e6
commit
2546bab0a6
3 files changed
+108
-2
No files matched your search
@@ -118,6 +118,9 @@ private const val CONTROLS_SECONDS = 4L
|
||||
/** How long the "up next" card counts down before it loads the next episode. */
|
||||
private const val UP_NEXT_SECONDS = 10
|
||||
|
||||
/** How close to the end the next episode's opening blocks are fetched. */
|
||||
private const val WARM_NEXT_SECONDS = 120.0
|
||||
|
||||
/** Past this much of an episode it counts as watched. */
|
||||
internal const val WATCHED_FRACTION = 0.9
|
||||
|
||||
@@ -360,6 +363,21 @@ fun PlayerScreen(
|
||||
if (!playingThis) return@remember null
|
||||
runCatching { skipOffer(chapters, state.position) }.getOrNull()
|
||||
}
|
||||
// Near the end, fetch the next episode's opening blocks, so autoplay or
|
||||
// "Play now" starts from the cache. The last two minutes or the credits,
|
||||
// whichever comes first: late enough that stopping after one episode has
|
||||
// not cost a download, early enough to matter.
|
||||
val nearEnd = playingThis && state.duration > 0.0 && (
|
||||
state.duration - state.position < WARM_NEXT_SECONDS ||
|
||||
chapters.creditsStart?.let { state.position >= it } == true
|
||||
)
|
||||
LaunchedEffect(key, nearEnd) {
|
||||
val upcoming = next ?: return@LaunchedEffect
|
||||
if (!nearEnd) return@LaunchedEffect
|
||||
runCatching {
|
||||
NativeRuntime.engine().warmEpisode(upcoming.shareId, upcoming.volumeId, upcoming.linkId)
|
||||
}
|
||||
}
|
||||
// Auto-skip is offered once per chapter: seeking back into an opening on
|
||||
// purpose must not be undone by the setting that skipped it.
|
||||
val skipped = remember(key) { mutableSetOf<Long>() }
|
||||
|
||||
Reference in new issue
Block a user