Do not shuffle album songs in onPlayFromMediaId
This commit is contained in:
@@ -24,7 +24,6 @@ import it.vfsfitvnm.vimusic.models.DetailedSong
|
|||||||
import it.vfsfitvnm.vimusic.models.PlaylistPreview
|
import it.vfsfitvnm.vimusic.models.PlaylistPreview
|
||||||
import it.vfsfitvnm.vimusic.utils.asMediaItem
|
import it.vfsfitvnm.vimusic.utils.asMediaItem
|
||||||
import it.vfsfitvnm.vimusic.utils.forcePlayAtIndex
|
import it.vfsfitvnm.vimusic.utils.forcePlayAtIndex
|
||||||
import it.vfsfitvnm.vimusic.utils.forcePlayFromBeginning
|
|
||||||
import it.vfsfitvnm.vimusic.utils.forceSeekToNext
|
import it.vfsfitvnm.vimusic.utils.forceSeekToNext
|
||||||
import it.vfsfitvnm.vimusic.utils.forceSeekToPrevious
|
import it.vfsfitvnm.vimusic.utils.forceSeekToPrevious
|
||||||
import it.vfsfitvnm.vimusic.utils.intent
|
import it.vfsfitvnm.vimusic.utils.intent
|
||||||
@@ -232,6 +231,7 @@ class PlayerMediaBrowserService : MediaBrowserService(), ServiceConnection {
|
|||||||
|
|
||||||
override fun onPlayFromMediaId(mediaId: String?, extras: Bundle?) {
|
override fun onPlayFromMediaId(mediaId: String?, extras: Bundle?) {
|
||||||
val data = mediaId?.split('/') ?: return
|
val data = mediaId?.split('/') ?: return
|
||||||
|
var index = 0
|
||||||
|
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
val mediaItems = when (data.getOrNull(0)) {
|
val mediaItems = when (data.getOrNull(0)) {
|
||||||
@@ -240,23 +240,14 @@ class PlayerMediaBrowserService : MediaBrowserService(), ServiceConnection {
|
|||||||
MediaId.songs -> data
|
MediaId.songs -> data
|
||||||
.getOrNull(1)
|
.getOrNull(1)
|
||||||
?.let { songId ->
|
?.let { songId ->
|
||||||
val index = lastSongs.indexOfFirst { it.id == songId }
|
index = lastSongs.indexOfFirst { it.id == songId }
|
||||||
|
lastSongs
|
||||||
if (index != -1) {
|
}
|
||||||
val mediaItems = lastSongs.map(DetailedSong::asMediaItem)
|
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
player.forcePlayAtIndex(mediaItems, index)
|
|
||||||
}
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
emptyList()
|
|
||||||
} ?: emptyList()
|
|
||||||
|
|
||||||
MediaId.favorites -> Database
|
MediaId.favorites -> Database
|
||||||
.favorites()
|
.favorites()
|
||||||
.first()
|
.first()
|
||||||
|
.shuffled()
|
||||||
|
|
||||||
MediaId.offline -> Database
|
MediaId.offline -> Database
|
||||||
.songsWithContentLength()
|
.songsWithContentLength()
|
||||||
@@ -266,25 +257,26 @@ class PlayerMediaBrowserService : MediaBrowserService(), ServiceConnection {
|
|||||||
cache.isCached(song.id, 0, song.contentLength)
|
cache.isCached(song.id, 0, song.contentLength)
|
||||||
} ?: false
|
} ?: false
|
||||||
}
|
}
|
||||||
|
.shuffled()
|
||||||
|
|
||||||
MediaId.playlists -> data
|
MediaId.playlists -> data
|
||||||
.getOrNull(1)
|
.getOrNull(1)
|
||||||
?.toLongOrNull()
|
?.toLongOrNull()
|
||||||
?.let { playlistId ->
|
?.let(Database::playlistWithSongs)
|
||||||
Database.playlistWithSongs(playlistId).first()?.songs
|
?.first()
|
||||||
} ?: emptyList()
|
?.songs
|
||||||
|
?.shuffled()
|
||||||
|
|
||||||
MediaId.albums -> data
|
MediaId.albums -> data
|
||||||
.getOrNull(1)
|
.getOrNull(1)
|
||||||
?.let { albumId ->
|
?.let(Database::albumSongs)
|
||||||
Database.albumSongs(albumId).first()
|
?.first()
|
||||||
} ?: emptyList()
|
|
||||||
|
|
||||||
else -> emptyList()
|
else -> emptyList()
|
||||||
}.map(DetailedSong::asMediaItem).shuffled()
|
}?.map(DetailedSong::asMediaItem) ?: return@launch
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
player.forcePlayFromBeginning(mediaItems)
|
player.forcePlayAtIndex(mediaItems, index.coerceIn(0, mediaItems.size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user