Skip to content

Commit

Permalink
Merge pull request #2778 from nextcloud/backport/2771/stable-15.1
Browse files Browse the repository at this point in the history
[stable-15.1] avoid NPE for voice message playback
  • Loading branch information
AndyScherzinger authored Feb 16, 2023
2 parents abeb937 + 291f527 commit cff95b3
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -982,25 +982,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)
mediaPlayer?.let {
if (!it.isPlaying) {
it.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)
}
mediaPlayerHandler.postDelayed(this, SECOND)
}
})
})

message.isDownloadingVoiceMessage = false
message.isPlayingVoiceMessage = true
adapter?.update(message)
message.isDownloadingVoiceMessage = false
message.isPlayingVoiceMessage = true
adapter?.update(message)
}
}

private fun pausePlayback(message: ChatMessage) {
Expand Down Expand Up @@ -1038,8 +1040,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!")
}
}

Expand Down

0 comments on commit cff95b3

Please sign in to comment.