mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
Handle the potential offset on the chunk position used by the media player
This commit is contained in:
parent
a0ab6de85a
commit
f74c7fa997
2 changed files with 13 additions and 9 deletions
|
@ -223,28 +223,32 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun startPlayback(position: Int) {
|
||||
private fun startPlayback(playbackPosition: Int) {
|
||||
stopPlayer()
|
||||
playingState = State.Buffering
|
||||
|
||||
val playlistItem = playlist.findByPosition(position) ?: run {
|
||||
Timber.w("## Voice Broadcast | No content to play at position $position"); stop(); return
|
||||
val playlistItem = playlist.findByPosition(playbackPosition) ?: run {
|
||||
Timber.w("## Voice Broadcast | No content to play at position $playbackPosition"); stop(); return
|
||||
}
|
||||
val sequence = playlistItem.sequence ?: run {
|
||||
Timber.w("## Voice Broadcast | Playlist item has no sequence"); stop(); return
|
||||
}
|
||||
val sequencePosition = position - playlistItem.startTime
|
||||
|
||||
currentVoiceBroadcast?.let {
|
||||
val percentage = tryOrNull { position.toFloat() / playlist.duration } ?: 0f
|
||||
playbackTracker.updatePausedAtPlaybackTime(it.voiceBroadcastId, position, percentage)
|
||||
val percentage = tryOrNull { playbackPosition.toFloat() / playlist.duration } ?: 0f
|
||||
playbackTracker.updatePausedAtPlaybackTime(it.voiceBroadcastId, playbackPosition, percentage)
|
||||
}
|
||||
|
||||
prepareCurrentPlayerJob = sessionScope.launch {
|
||||
try {
|
||||
val mp = prepareMediaPlayer(playlistItem.audioEvent.content)
|
||||
playlist.currentSequence = sequence - 1 // will be incremented in onNextMediaPlayerStarted
|
||||
|
||||
// Take the difference between the duration given from the media player and the duration given from the chunk event
|
||||
// If the offset is smaller than 500ms, we consider there is no offset to keep the normal behaviour
|
||||
val offset = (mp.duration - playlistItem.duration).takeUnless { it < 500 }?.coerceAtLeast(0) ?: 0
|
||||
val sequencePosition = offset + (playbackPosition - playlistItem.startTime)
|
||||
|
||||
playlist.currentSequence = sequence - 1 // will be incremented in onNextMediaPlayerStarted
|
||||
mp.start()
|
||||
if (sequencePosition > 0) {
|
||||
mp.seekTo(sequencePosition)
|
||||
|
|
|
@ -65,6 +65,6 @@ class VoiceBroadcastPlaylist(
|
|||
}
|
||||
|
||||
data class PlaylistItem(val audioEvent: MessageAudioEvent, val startTime: Int) {
|
||||
val sequence: Int?
|
||||
get() = audioEvent.sequence
|
||||
val sequence: Int? = audioEvent.sequence
|
||||
val duration: Int = audioEvent.duration
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue