avoid IllegalStateException for ChatController#stopMediaPlayer

didn't see this crash here, but it might have happened similar to b29fccac where it happened.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-02-09 10:44:26 +01:00
parent bad8e2a705
commit be5a60dc77
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -1036,9 +1036,18 @@ class ChatController(args: Bundle) :
mediaPlayerHandler.removeCallbacksAndMessages(null)
mediaPlayer?.stop()
mediaPlayer?.release()
mediaPlayer = null
try {
mediaPlayer?.let {
if (it.isPlaying) {
it.stop()
}
}
} catch (e: IllegalStateException) {
Log.e(TAG, "mediaPlayer was not initialized", e)
} finally {
mediaPlayer?.release()
mediaPlayer = null
}
}
override fun updateMediaPlayerProgressBySlider(messageWithSlidedProgress: ChatMessage, progress: Int) {
@ -3426,6 +3435,7 @@ class ChatController(args: Bundle) :
private const val VOICE_RECORD_CANCEL_SLIDER_X: Int = -50
private const val VOICE_MESSAGE_META_DATA = "{\"messageType\":\"voice-message\"}"
private const val VOICE_MESSAGE_FILE_SUFFIX = ".mp3"
// Samplingrate 22050 was chosen because somehow 44100 failed to playback on safari when recorded on android.
// Please test with firefox, chrome, safari and mobile clients if changing anything regarding the sound.
private const val VOICE_MESSAGE_SAMPLING_RATE = 22050