From 4f9016713fe3aaaffaff9a6a37f0b3d7f70d96a1 Mon Sep 17 00:00:00 2001 From: Shif-Jess <117321707+Shif-Jess@users.noreply.github.com> Date: Sun, 9 Apr 2023 14:37:27 +0700 Subject: [PATCH] CS3Player: fixed ERROR_CODE_BEHIND_LIVE_WINDOW (#447) --- .../cloudstream3/ui/player/CS3IPlayer.kt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt index e0885671..9accf15e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt @@ -985,12 +985,19 @@ class CS3IPlayer : IPlayer { // If the Network fails then ignore the exception if the duration is set. // This is to switch mirrors automatically if the stream has not been fetched, but // allow playing the buffer without internet as then the duration is fetched. - if (error.errorCode == PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED - && exoPlayer?.duration != TIME_UNSET - ) { - exoPlayer?.prepare() - } else { - playerError?.invoke(error) + when { + error.errorCode == PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED + && exoPlayer?.duration != TIME_UNSET -> { + exoPlayer?.prepare() + } + error.errorCode == PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW -> { + // Re-initialize player at the current live window default position. + exoPlayer?.seekToDefaultPosition() + exoPlayer?.prepare() + } + else -> { + playerError?.invoke(error) + } } super.onPlayerError(error)