Merge branch 'shuffleCrash2' into 'develop'

Prevent a media3 crash

See merge request ultrasonic/ultrasonic!1064
This commit is contained in:
birdbird 2023-06-27 08:22:57 +00:00
commit c42439ef69
4 changed files with 10 additions and 9 deletions

View File

@ -135,7 +135,6 @@ abstract class EntryListFragment<T : GenericEntry> : MultiListFragment<T>() {
item.id,
append = false,
autoPlay = true,
shuffle = false,
playNext = false,
isArtist = isArtist
)
@ -145,7 +144,6 @@ abstract class EntryListFragment<T : GenericEntry> : MultiListFragment<T>() {
item.id,
append = false,
autoPlay = true,
shuffle = true,
playNext = true,
isArtist = isArtist
)
@ -155,7 +153,6 @@ abstract class EntryListFragment<T : GenericEntry> : MultiListFragment<T>() {
item.id,
append = true,
autoPlay = false,
shuffle = false,
playNext = false,
isArtist = isArtist
)

View File

@ -316,7 +316,6 @@ open class TrackCollectionFragment(
append = append,
playNext = false,
autoPlay = !append,
shuffle = false,
playlistName = null,
fragment = this
)
@ -616,7 +615,6 @@ open class TrackCollectionFragment(
append = true,
playNext = true,
autoPlay = false,
shuffle = false,
playlistName = navArgs.playlistName,
fragment = this@TrackCollectionFragment
)

View File

@ -429,7 +429,10 @@ class MediaPlayerManager(
when (insertionMode) {
InsertionMode.CLEAR -> clear()
InsertionMode.APPEND -> insertAt = mediaItemCount
InsertionMode.AFTER_CURRENT -> insertAt = currentMediaItemIndex + 1
InsertionMode.AFTER_CURRENT -> {
// Must never be larger than the count of items (especially when empty)
insertAt = (currentMediaItemIndex + 1).coerceAtMost(mediaItemCount)
}
}
val mediaItems: List<MediaItem> = songs.map {
@ -437,10 +440,13 @@ class MediaPlayerManager(
result
}
if (shuffle) isShufflePlayEnabled = true
Timber.w("Adding ${mediaItems.size} media items")
controller?.addMediaItems(insertAt, mediaItems)
// There is a bug in media3 ( https://github.com/androidx/media/issues/480 ),
// so we must first add the tracks, and then enable shuffle
if (shuffle) isShufflePlayEnabled = true
prepare()
// Playback doesn't start correctly when the player is in STATE_ENDED.

View File

@ -98,7 +98,7 @@ class DownloadHandler(
isDirectory: Boolean = true,
append: Boolean,
autoPlay: Boolean,
shuffle: Boolean,
shuffle: Boolean = false,
playNext: Boolean,
isArtist: Boolean = false
) {
@ -141,7 +141,7 @@ class DownloadHandler(
append: Boolean,
playNext: Boolean,
autoPlay: Boolean,
shuffle: Boolean,
shuffle: Boolean = false,
playlistName: String? = null,
fragment: Fragment
) {