Improve player transitions

This commit is contained in:
Florian Renaud 2022-10-31 18:42:52 +01:00
parent eb61a23bf6
commit b41346cdce

View file

@ -63,10 +63,6 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
private var currentMediaPlayer: MediaPlayer? = null
private var nextMediaPlayer: MediaPlayer? = null
set(value) {
field = value
currentMediaPlayer?.setNextMediaPlayer(value)
}
private var currentSequence: Int? = null
private var fetchPlaylistJob: Job? = null
@ -303,7 +299,7 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
}
}
private inner class MediaPlayerListener : MediaPlayer.OnInfoListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
private inner class MediaPlayerListener : MediaPlayer.OnInfoListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
override fun onInfo(mp: MediaPlayer, what: Int, extra: Int): Boolean {
when (what) {
@ -317,6 +313,17 @@ class VoiceBroadcastPlayerImpl @Inject constructor(
return false
}
override fun onPrepared(mp: MediaPlayer) {
when (mp) {
currentMediaPlayer -> {
nextMediaPlayer?.let { mp.setNextMediaPlayer(it) }
}
nextMediaPlayer -> {
tryOrNull { currentMediaPlayer?.setNextMediaPlayer(mp) }
}
}
}
override fun onCompletion(mp: MediaPlayer) {
if (nextMediaPlayer != null) return
val roomId = currentRoomId ?: return