Skip to content

Commit 6f24c8f

Browse files
authored
fix(android): reset prepared state on player error (#1425)
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
1 parent aee480b commit 6f24c8f

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player

packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ class WrappedPlayer internal constructor(
266266
}
267267

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

0 commit comments

Comments
 (0)