I have a music app I have coded using Swift and I have found a bug that Apple has acknowledged as a bug on their end.
In the app I can tap a button and play songs based on the currently playing song. I am using prepend to create queue's. So for example when I want to add a specific genre to the queue I use
let lockArtist = MediaManager.shared.getSongsWithCurrentArtistFor(item: nowPlaying)
if var items = lockArtist.items {
items.shuffle()
let descriptor = MPMusicPlayerMediaItemQueueDescriptor(itemCollection: MPMediaItemCollection(items: items))
self.mediaPlayer.prepend(descriptor)
}
The MediaManager.shared.getSongsWithCurrentArtistFor
is
func getSongsWithCurrentArtistFor(item: MPMediaItem) -> MPMediaQuery {
let artistPredicate = MPMediaPropertyPredicate(value: item.artist, forProperty: MPMediaItemPropertyArtist, comparisonType: .contains)
let query = MPMediaQuery()
query.addFilterPredicate(artistPredicate)
return query
}
.
This code works! It adds the genre to the queue but it does not keep track of the queue. I'll explain
.
What I expect to happen is song 1 comes on, then song 2, then song 3, and so on. From Song 3 if I tapped the back button I would expect to go back to song 2 and then the forward button would go forward to song 3.
What actually happens is song 1 comes on, then song 2, then song 3 and when I tap the back button from song 3 it DOES NOT go back to song 2 but instead a random song and tapping the forward button does not go to song 3 but another random song.
The first back song button tap will usually stay within the genre but the next will go to the song I was playing before I tapped the button that used the prepend code.
I filed a code level support ticket with Apple and after a while the engineer said the issue is not with me but on Apple's end and instructed me to file a bug report also and include the ticket # and they would help find a work around. That was **2 months* ago and I never heard back.
I was hoping somebody could help.