From 6f24c8f57e4549edbf7d68a021d1d94371c23f3f Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Tue, 14 Feb 2023 14:43:47 +0100 Subject: [PATCH] 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 --- .../main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt b/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt index 9018e2d79..853574e29 100644 --- a/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt +++ b/packages/audioplayers_android/android/src/main/kotlin/xyz/luan/audioplayers/player/WrappedPlayer.kt @@ -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 {