Skip to content

Commit f7494f2

Browse files
authored
Support resuming fragmented MP4s (#2690)
1 parent 590a94e commit f7494f2

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

  • app/src/main/java/com/lagradost/cloudstream3/ui/player

app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,23 @@ class CS3IPlayer : IPlayer {
14301430
event(PlayerAttachedEvent(exoPlayer))
14311431
exoPlayer?.prepare()
14321432

1433+
// For offline fragmented MP4s, FLAG_MERGE_FRAGMENTED_SIDX builds the SIDX seek map
1434+
// incrementally as data is buffered. The initial seek resolves to the nearest merged
1435+
// entry (~first fragment, 3 s). On STATE_READY, re-seek to the actual saved position.
1436+
// This may only be reproducible on large and fairly long fragmented MP4 files with
1437+
// multiple sidx boxes.
1438+
if (onlineSource == null && playbackPosition > (exoPlayer?.duration ?: 0L)) {
1439+
exoPlayer?.addListener(object : Player.Listener {
1440+
private var seekApplied = false
1441+
override fun onPlaybackStateChanged(playbackState: Int) {
1442+
if (seekApplied || playbackState != Player.STATE_READY) return
1443+
seekApplied = true
1444+
exoPlayer?.seekTo(currentWindow, playbackPosition)
1445+
exoPlayer?.removeListener(this)
1446+
}
1447+
})
1448+
}
1449+
14331450
exoPlayer?.let { exo ->
14341451
event(StatusEvent(CSPlayerLoading.IsBuffering, CSPlayerLoading.IsBuffering))
14351452
isPlaying = exo.isPlaying

0 commit comments

Comments
 (0)