mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 03:29:28 +01:00
better null and error handling in the seekbar update observer
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
This commit is contained in:
parent
a361240692
commit
a7f742931e
@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user