Merge pull request #2771 from nextcloud/bugfix/noid/fixNpeVoiceMessagePlayback

avoid NPE for voice message playback
This commit is contained in:
Marcel Hibbe 2023-02-16 15:20:10 +01:00 committed by GitHub
commit 989e3fe211
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -975,25 +975,27 @@ class ChatController(args: Bundle) :
initMediaPlayer(message)
if (!mediaPlayer!!.isPlaying) {
mediaPlayer!!.start()
}
mediaPlayerHandler = Handler()
activity?.runOnUiThread(object : Runnable {
override fun run() {
if (mediaPlayer != null) {
val currentPosition: Int = mediaPlayer!!.currentPosition / VOICE_MESSAGE_SEEKBAR_BASE
message.voiceMessagePlayedSeconds = currentPosition
adapter?.update(message)
}
mediaPlayerHandler.postDelayed(this, SECOND)
mediaPlayer?.let {
if (!it.isPlaying) {
it.start()
}
})
message.isDownloadingVoiceMessage = false
message.isPlayingVoiceMessage = true
adapter?.update(message)
mediaPlayerHandler = Handler()
activity?.runOnUiThread(object : Runnable {
override fun run() {
if (mediaPlayer != null) {
val currentPosition: Int = mediaPlayer!!.currentPosition / VOICE_MESSAGE_SEEKBAR_BASE
message.voiceMessagePlayedSeconds = currentPosition
adapter?.update(message)
}
mediaPlayerHandler.postDelayed(this, SECOND)
}
})
message.isDownloadingVoiceMessage = false
message.isPlayingVoiceMessage = true
adapter?.update(message)
}
}
private fun pausePlayback(message: ChatMessage) {
@ -1031,8 +1033,6 @@ class ChatController(args: Bundle) :
Log.e(TAG, "failed to initialize mediaPlayer", e)
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
}
} else {
Log.e(TAG, "mediaPlayer was not null. This should not happen!")
}
}