This commit is contained in:
Benoit Marty 2021-07-13 15:54:09 +02:00
parent bff2c6ea93
commit 6283846108

View file

@ -206,29 +206,23 @@ class VoiceMessageHelper @Inject constructor(
playbackTimer = CountUpTimer().apply {
tickListener = object : CountUpTimer.TickListener {
override fun onTick(milliseconds: Long) {
onPlaybackTimerTick(id, false)
onPlaybackTimerTick(id)
}
}
resume()
}
onPlaybackTimerTick(id, true)
onPlaybackTimerTick(id)
}
private fun onPlaybackTimerTick(id: String, firstCall: Boolean) {
when {
firstCall -> {
playbackTracker.updateCurrentPlaybackTime(id, 0)
}
mediaPlayer?.isPlaying.orFalse() -> {
private fun onPlaybackTimerTick(id: String) {
if (mediaPlayer?.isPlaying.orFalse()) {
val currentPosition = mediaPlayer?.currentPosition ?: 0
playbackTracker.updateCurrentPlaybackTime(id, currentPosition)
}
else -> {
} else {
playbackTracker.stopPlayback(id)
stopPlaybackTimer()
}
}
}
private fun stopPlaybackTimer() {
playbackTimer?.stop()