First item in queue plays when different item is selected

Number:rdar://7433934 Date Originated:07-Nov-2019
Status:Open Resolved:
Product:iOS + Media Player Framework Product Version:
Classification: Reproducible:Yes
It all starts by invoking my function `setPlayerQueue(with storeIds: [String], start index: Int)` (see below) from the `didSelectItemAt` UICollectionViewDelegate method. This is expected to enqueue the store ids in an order that matches the display of tracks in the UICollectionView. So if cell 15 is tapped, track 15 should play. What actually happens is that track 1 plays first, and if I tap again, then track 15 will play as expected.

When I tap a cell in my UICollectionView, a queue is created using an array of store ids via the `func setQueue(with descriptor: MPMusicPlayerQueueDescriptor)`. I also assign the MPMusicPlayerQueueDescriptor `startItemID` property to the store id associated with the selected index path before invoking `setQueue(descriptor)`.

1. Create array of store ids (e.g. 20 tracks)
2. Scroll to bottom of UICollectionView (e.g. 20 items)
3. Call `setPlayerQueue(with: storeIds, start: indexPath.item)` (see below) by selecting any cell (e.g. index 17)
4. Call `prepareToPlay()`, followed by `play()` in its closure

func setPlayerQueue(with storeIds: [String], start index: Int) {
        let descriptor: MPMusicPlayerStoreQueueDescriptor = MPMusicPlayerStoreQueueDescriptor(storeIDs: storeIds)
        descriptor.startItemID = storeIds[index]
        player.setQueue(with: descriptor) // player: MPMusicPlayerController.applicationMusicPlayer

Expected Results:
Track at index 17 plays.

Actual Results:
Track at index 1 plays. Tap again, and track 17 plays.


I have found a workaround:

By harmankang97 at Nov. 9, 2019, 4:10 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!