Merge pull request #5060 from nextcloud/backport/5053/stable-21.1

[stable-21.1] Better null and error handling when playing voice messages
This commit is contained in:
Marcel Hibbe 2025-06-13 14:12:44 +00:00 committed by GitHub
commit d1b3e7cb4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 9 deletions

View File

@ -183,19 +183,26 @@ class MediaPlayerManager : LifecycleAwareManager {
continue continue
} }
if (mediaPlayer != null && mediaPlayer?.isPlaying == true) { mediaPlayer?.let { player ->
val pos = mediaPlayer!!.currentPosition try {
if (!player.isPlaying) return@let
} catch (e: IllegalStateException) {
Log.e(TAG, "Seekbar updated during an improper state: $e")
return@let
}
val pos = player.currentPosition
mediaPlayerPosition = pos mediaPlayerPosition = pos
val progress = (pos.toFloat() / mediaPlayerDuration) * DIVIDER val progress = (pos.toFloat() / mediaPlayerDuration) * DIVIDER
val progressI = ceil(progress).toInt() val progressI = ceil(progress).toInt()
val seconds = (pos / ONE_SEC) val seconds = (pos / ONE_SEC)
_mediaPlayerSeekBarPosition.emit(progressI) _mediaPlayerSeekBarPosition.emit(progressI)
currentCycledMessage?.let { currentCycledMessage?.let { msg ->
it.isPlayingVoiceMessage = true msg.isPlayingVoiceMessage = true
it.voiceMessageSeekbarProgress = progressI msg.voiceMessageSeekbarProgress = progressI
it.voiceMessagePlayedSeconds = seconds msg.voiceMessagePlayedSeconds = seconds
if (progressI >= IS_PLAYED_CUTOFF) it.wasPlayedVoiceMessage = true if (progressI >= IS_PLAYED_CUTOFF) msg.wasPlayedVoiceMessage = true
_mediaPlayerSeekBarPositionMsg.emit(it) _mediaPlayerSeekBarPositionMsg.emit(msg)
} }
} }

View File

@ -1,2 +1,2 @@
DO NOT TOUCH; GENERATED BY DRONE DO NOT TOUCH; GENERATED BY DRONE
<span class="mdl-layout-title">Lint Report: 10 errors and 99 warnings</span> <span class="mdl-layout-title">Lint Report: 10 errors and 100 warnings</span>