There is an answer on this question: iOS - get programatically queue of items currently playing that describes how to do this, however I am trying that method and it does not work. Here is my code:
let numberOfItems = player.value(forKey: "numberOfItems") as! Int
for i in 0..<numberOfItems {
if let mediaItem = MPMusicPlayerController.systemMusicPlayer.perform(Selector("nowPlayingItemAtIndex:"), with: i)?.takeUnretainedValue() as? MPMediaItem {
let songObject = mediaItem.value(forKey: "propertyValues") as! NSObject
print(songObject.value(forKey: "title"))
print(mediaItem.title)
print(mediaItem.value(forKey: "title"))
print(mediaItem.value(forProperty: MPMediaItemPropertyTitle))
}
}
All 4 print statements are nil. It is worth noting that it can indeed cast the item as an MPMediaItem, and the songObject variable actually prints as a MPModelSong. The runtime headers indicate there is a property on MPModelSong objects "title" (found here: https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MediaPlayer.framework/MPModelSong.h)
No matter what, everything prints nil. Any idea what direction I should head from here?