Skip to content

Commit

Permalink
fix(android): reset prepared state on player error (#1425)
Browse files Browse the repository at this point in the history
In the rare case, that an media player error occurs (like when playing
unsupported media sources), the player still is in the "prepared" state,
although the internal MediaPlayer state isn't anymore. Then it could keep
calling methods, which lead to an illegal MediaPlayer state. By
resetting this variable on a media error, this should not make the
library crash anymore, but still emit the error.

Fixes #1260
Fixes #1331
  • Loading branch information
Gustl22 authored Feb 14, 2023
1 parent aee480b commit 6f24c8f
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ class WrappedPlayer internal constructor(
}

fun onError(what: Int, extra: Int): Boolean {
// When an error occurs, reset player to not [prepared].
// Then no functions will be called, which end up in an illegal player state.
prepared = false
val whatMsg = if (what == MediaPlayer.MEDIA_ERROR_SERVER_DIED) {
"MEDIA_ERROR_SERVER_DIED"
} else {
Expand Down

0 comments on commit 6f24c8f

Please sign in to comment.