Skip to content

Commit

Permalink
player: better fix for seamless playback
Browse files Browse the repository at this point in the history
  • Loading branch information
Millencolin committed Jan 31, 2025
1 parent bf13ecc commit 85ef35a
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions app/src/main/java/com/dd3boh/outertune/models/QueueBoard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.media3.common.C
import androidx.media3.common.MediaItem
import com.dd3boh.outertune.constants.PersistentQueueKey
import com.dd3boh.outertune.db.entities.QueueEntity
import com.dd3boh.outertune.extensions.mediaItems
import com.dd3boh.outertune.extensions.metadata
import com.dd3boh.outertune.extensions.move
import com.dd3boh.outertune.extensions.toMediaItem
Expand Down Expand Up @@ -714,7 +713,7 @@ class QueueBoard(queues: MutableList<MultiQueueObject> = ArrayList()) {
mediaItems = item.unShuffled
}

val allowSeamlessPlayback = allowSeamlessPlayback(player, mediaItems)
val allowSeamlessPlayback = allowSeamlessPlayback(player, mediaItems, queuePos)

setMediaItems(mediaItems, player, allowSeamlessPlayback)
isShuffleEnabled.value = item.shuffled
Expand All @@ -733,30 +732,21 @@ class QueueBoard(queues: MutableList<MultiQueueObject> = ArrayList()) {
*/
private fun allowSeamlessPlayback(
player: MusicService,
mediaItems: List<MediaMetadata>
mediaItems: List<MediaMetadata>,
queuePos: Int
): Boolean {
if (!player.player.isPlaying) {
return false
}
val currentSongId = player.currentMediaMetadata.value?.id ?: return false

if (matchingMediaItems(mediaItems, player)) {
if (queuePos != 0) {
return false
}

return mediaItems.firstOrNull()?.id.equals(currentSongId)
}

private fun matchingMediaItems(
mediaItems: List<MediaMetadata>,
player: MusicService
): Boolean {
if (mediaItems.size != player.player.mediaItems.size) {
return false
}
return player.player.mediaItems.map { it.mediaId } == mediaItems.map { it.id }
}

/**
* Sets the media items. If the first media item matches the currently playing song it will
* switches to the new list of items without interrupting playback otherwise it replaces the
Expand Down

0 comments on commit 85ef35a

Please sign in to comment.