Make possible to start the radio from the currently playing song (#118)

This commit is contained in:
vfsfitvnm
2022-07-22 15:20:38 +02:00
parent 3b9b5a5124
commit dd200e1374
3 changed files with 63 additions and 46 deletions

View File

@@ -18,6 +18,15 @@ val Timeline.windows: List<Timeline.Window>
val Player.shouldBePlaying: Boolean
get() = !(playbackState == Player.STATE_ENDED || !playWhenReady)
fun Player.seamlessPlay(mediaItem: MediaItem) {
if (mediaItem.mediaId == currentMediaItem?.mediaId) {
if (currentMediaItemIndex > 0) removeMediaItems(0, currentMediaItemIndex)
if (currentMediaItemIndex < mediaItemCount - 1) removeMediaItems(currentMediaItemIndex + 1, mediaItemCount)
} else {
forcePlay(mediaItem)
}
}
fun Player.forcePlay(mediaItem: MediaItem) {
setMediaItem(mediaItem, true)
playWhenReady = true