Fix:Android crash when attempting sync after exoplayer failed

This commit is contained in:
advplyr 2022-08-10 18:27:37 -05:00
parent 1aea0a18a9
commit 40b731534c
2 changed files with 7 additions and 7 deletions

View file

@ -74,14 +74,14 @@ class MediaProgressSyncer(val playerNotificationService:PlayerNotificationServic
}
}
fun stop(cb: () -> Unit) {
fun stop(shouldSync:Boolean? = true, cb: () -> Unit) {
if (!listeningTimerRunning) return
listeningTimerTask?.cancel()
listeningTimerTask = null
listeningTimerRunning = false
Log.d(tag, "stop: Stopping listening for $currentDisplayTitle")
val currentTime = playerNotificationService.getCurrentTimeSeconds()
val currentTime = if (shouldSync == true) playerNotificationService.getCurrentTimeSeconds() else 0.0
if (currentTime > 0) { // Current time should always be > 0 on stop
sync(true, currentTime) {
reset()

View file

@ -438,7 +438,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
apiHandler.playLibraryItem(libraryItemId, episodeId, playItemRequestPayload) {
if (it == null) { // Play request failed
clientEventEmitter?.onPlaybackFailed(errorMessage)
closePlayback()
closePlayback(true)
} else {
Handler(Looper.getMainLooper()).post {
preparePlayer(it, true, null)
@ -447,7 +447,7 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
}
} else {
clientEventEmitter?.onPlaybackFailed(errorMessage)
closePlayback()
closePlayback(true)
}
}
}
@ -705,12 +705,12 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
currentPlayer.setPlaybackSpeed(speed)
}
fun closePlayback() {
fun closePlayback(calledOnError:Boolean? = false) {
Log.d(tag, "closePlayback")
if (mediaProgressSyncer.listeningTimerRunning) {
Log.i(tag, "About to close playback so stopping media progress syncer first")
mediaProgressSyncer.stop {
Log.d(tag, "Media Progress syncer stopped and synced")
mediaProgressSyncer.stop(calledOnError == false) { // If closing on error then do not sync progress (causes exception)
Log.d(tag, "Media Progress syncer stopped")
}
}