Fix seek on paused state
This commit is contained in:
parent
b2f35fa135
commit
436e76c756
@ -133,7 +133,7 @@ sealed class RoomDetailAction : VectorViewModelAction {
|
||||
data class PlayOrResume(val voiceBroadcast: VoiceBroadcast) : Listening()
|
||||
object Pause : Listening()
|
||||
object Stop : Listening()
|
||||
data class SeekTo(val voiceBroadcast: VoiceBroadcast, val positionMillis: Int) : Listening()
|
||||
data class SeekTo(val voiceBroadcast: VoiceBroadcast, val positionMillis: Int, val duration: Int) : Listening()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -637,7 +637,7 @@ class TimelineViewModel @AssistedInject constructor(
|
||||
is VoiceBroadcastAction.Listening.PlayOrResume -> voiceBroadcastHelper.playOrResumePlayback(action.voiceBroadcast)
|
||||
VoiceBroadcastAction.Listening.Pause -> voiceBroadcastHelper.pausePlayback()
|
||||
VoiceBroadcastAction.Listening.Stop -> voiceBroadcastHelper.stopPlayback()
|
||||
is VoiceBroadcastAction.Listening.SeekTo -> voiceBroadcastHelper.seekTo(action.voiceBroadcast, action.positionMillis)
|
||||
is VoiceBroadcastAction.Listening.SeekTo -> voiceBroadcastHelper.seekTo(action.voiceBroadcast, action.positionMillis, action.duration)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ abstract class MessageVoiceBroadcastListeningItem : AbsMessageVoiceBroadcastItem
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
||||
callback?.onTimelineItemAction(VoiceBroadcastAction.Listening.SeekTo(voiceBroadcast, seekBar.progress))
|
||||
callback?.onTimelineItemAction(VoiceBroadcastAction.Listening.SeekTo(voiceBroadcast, seekBar.progress, duration))
|
||||
isUserSeeking = false
|
||||
}
|
||||
})
|
||||
|
@ -48,7 +48,7 @@ class VoiceBroadcastHelper @Inject constructor(
|
||||
|
||||
fun stopPlayback() = voiceBroadcastPlayer.stop()
|
||||
|
||||
fun seekTo(voiceBroadcast: VoiceBroadcast, positionMillis: Int) {
|
||||
voiceBroadcastPlayer.seekTo(voiceBroadcast, positionMillis)
|
||||
fun seekTo(voiceBroadcast: VoiceBroadcast, positionMillis: Int, duration: Int) {
|
||||
voiceBroadcastPlayer.seekTo(voiceBroadcast, positionMillis, duration)
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ interface VoiceBroadcastPlayer {
|
||||
/**
|
||||
* Seek the given voice broadcast playback to the given position, is milliseconds.
|
||||
*/
|
||||
fun seekTo(voiceBroadcast: VoiceBroadcast, positionMillis: Int)
|
||||
fun seekTo(voiceBroadcast: VoiceBroadcast, positionMillis: Int, duration: Int)
|
||||
|
||||
/**
|
||||
* Add a [Listener] to the given voice broadcast.
|
||||
|
@ -94,8 +94,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
||||
}
|
||||
|
||||
override fun pause() {
|
||||
currentMediaPlayer?.pause()
|
||||
playingState = State.PAUSED
|
||||
pausePlayback()
|
||||
}
|
||||
|
||||
override fun stop() {
|
||||
@ -212,16 +211,39 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun resumePlayback() {
|
||||
currentMediaPlayer?.start()
|
||||
playingState = State.PLAYING
|
||||
private fun pausePlayback(positionMillis: Int? = null) {
|
||||
if (positionMillis == null) {
|
||||
currentMediaPlayer?.pause()
|
||||
} else {
|
||||
stopPlayer()
|
||||
currentVoiceBroadcast?.voiceBroadcastId?.let { id ->
|
||||
playbackTracker.updatePausedAtPlaybackTime(id, positionMillis, positionMillis.toFloat() / playlist.duration)
|
||||
}
|
||||
}
|
||||
playingState = State.PAUSED
|
||||
}
|
||||
|
||||
override fun seekTo(voiceBroadcast: VoiceBroadcast, positionMillis: Int) {
|
||||
if (voiceBroadcast != currentVoiceBroadcast) {
|
||||
playbackTracker.updatePausedAtPlaybackTime(voiceBroadcast.voiceBroadcastId, positionMillis, 0f)
|
||||
private fun resumePlayback() {
|
||||
if (currentMediaPlayer != null) {
|
||||
currentMediaPlayer?.start()
|
||||
playingState = State.PLAYING
|
||||
} else {
|
||||
startPlayback(positionMillis)
|
||||
val position = currentVoiceBroadcast?.voiceBroadcastId?.let { playbackTracker.getPlaybackTime(it) }
|
||||
startPlayback(position)
|
||||
}
|
||||
}
|
||||
|
||||
override fun seekTo(voiceBroadcast: VoiceBroadcast, positionMillis: Int, duration: Int) {
|
||||
when {
|
||||
voiceBroadcast != currentVoiceBroadcast -> {
|
||||
playbackTracker.updatePausedAtPlaybackTime(voiceBroadcast.voiceBroadcastId, positionMillis, positionMillis.toFloat() / duration)
|
||||
}
|
||||
playingState == State.PLAYING || playingState == State.BUFFERING -> {
|
||||
startPlayback(positionMillis)
|
||||
}
|
||||
playingState == State.IDLE || playingState == State.PAUSED -> {
|
||||
pausePlayback(positionMillis)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user