1

I'm making a music player app that can access and play music and playlists that come from Apple Music and the iOS music library, and I want to be able to save and reload the user's song queue across app launches. If a song is locally stored on a phone, it's easy enough to save its MPMediaItem.persistentID and then load the item back up using a predicate like this:

let predicate = MPMediaPropertyPredicate(value: savedLocalID, forProperty: MPMediaItemPropertyPersistentID);
let songQuery = MPMediaQuery.init(filterPredicates: [predicate]);

However, with songs that come from playlists saved from Apple music, their MPMediaItem.persistentID isn't preserved across app launches and doesn't work to load them as MPMediaItems. I was hoping that MPMediaItem.playbackStoreID could be used in a similar way with MPMediaQuery, but when I try to make a predicate using it with MPMediaItemPropertyPlaybackStoreID I get the error "MPMediaPropertyPredicate cannot filter using the playbackStoreID property." Any ideas how to get an MPMediaItem from a saved MPMediaItem.playbackStoreID, or another property I'm missing that works for non-local Apple Music files? Thanks!

Thomas
  • 485
  • 4
  • 15
  • https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/AppleMusicWebServicesReference/index.html – matt Feb 16 '18 at 22:02
  • All I can find in Apple's documentation is how to use that playbackStoreID to get info about an item using an https request, not how to get a playable MPMediaItem. – Thomas Feb 16 '18 at 22:04
  • Right, so similar to the complaint made here: http://www.openradar.me/28569390 – matt Feb 16 '18 at 22:08
  • 2
    Hmm, so sounds like at least as of iOS 9.3 you can set a playlist that uses all playbackStoreIDs (which local files don't have) but you can't necessarily get MPMediaItems from playbackStoreIDs. I can't believe how idiotic Apple is with this set of APIs. – Thomas Feb 16 '18 at 22:22
  • I mean, i can believe it by this point... – Thomas Feb 16 '18 at 22:23
  • Well, I don't know that it's idiotic, because after all the song might be remote. You can't just hand an MPMediaItem to a player if the item isn't there to begin with. That's why we now have APIs like [MPMusicPlayerStoreQueueDescriptor](https://developer.apple.com/documentation/mediaplayer/mpmusicplayerstorequeuedescriptor). You use this to set the queue of the `applicationQueuePlayer`. Perhaps that's what you're looking for? – matt Feb 16 '18 at 22:29
  • Might help to watch https://developer.apple.com/videos/play/wwdc2017/502/ – matt Feb 16 '18 at 22:33
  • 1
    Well I can get these as MPMediaItems when the user selects a playlist that contains them, even though they're remote, and can play them like I can local files. I think it really is dumb on Apple's part :]. I'll take a look at that video, thanks! – Thomas Feb 16 '18 at 23:44
  • Also, that MPMusicPlayerStoreQueueDescriptor looks like it only works if all the items have storeIDs, which lots of local files may not. – Thomas Feb 16 '18 at 23:46

0 Answers0