Exposing library-related metadata on library Songs

I have been excitedly testing out MusicKit's new features to interact with a user's music library over the last couple of days. Albums and Songs are a much nicer paradigm than MPMediaItemCollection and MPMediaItem, but I'm afraid that there are some library-focused metadata options present on MPMediatem that are seemingly not currently exposed on Songs fetched from a MusicLibraryRequest that force me back into the world of MPMediaItems.

A big component of my app is being able to sort and filter your library across properties like play count and date added. Am I right that these properties are not available when interacting with library Songs in MusicKit?

  • dateAdded - The date the item was added to the library
  • lastPlayTime - The date on which the item was last played
  • playCount - The number of times the item has been played

For as long as those properties are not available, I will need to dip back into MPMediaItems in order to continue offering important pieces of functionality in my app. 

Those three are my highest priority for this area of MusicKit at this time, and are my biggest blockers on jumping into the new world as opposed to staying the old. I've submitted the above as FB10185523

While I'm at it, I also have a wishlist of some additional properties, only one of which is currently exposed on MPMediaItem. The rest of which correspond to metadata a user can set in Music.app on the desktop but have not historically been publicly exposed on MPMediaItem:

  • isCloudItem - This is currently exposed on MPMediaItem and tells you whether an item is locally downloaded on the device. I understand that the includeOnlyDownloadedContent option can be set on a MusicLibraryRequest to return locally downloaded devices, but it would also be nice to have on a per-song basis to be able to display an indicator to the user. 
  • startTime and stopTime - These properties correspond to the custom “start” and “stop” times a user can define for a song on the Options tab of Music.app on the desktop. These have not historically been exposed publicly. It would be nice to have access to these in order to be able to display an accurate play time if a user has customized it.
  • sortAlbumTitle, sortAlbumArtist, sortArtist - These properties correspond to the “sort as” options a user can define for a song on the Sorting tab of Music.app on the desktop. These have not historically been exposed publicly. It would be nice to have access to these in order to display library items to a user in the order they’ve defined and expect, rather than ignore their preference. 

I've submitted the above as FB10185575

Thanks!

Answered by Frameworks Engineer in 719622022

Hello @talkingsmall and @snuff4,

We made a number of important improvements to the list of available properties for items retrieved from the music library. You can find those in iOS 16 Beta 3, which just we just released today.

For example, the Song type now includes the following attributes:

I hope you'll find this useful.

Best regards,

I agree. I can see a lot of use-case for these three properties in my app as well and would love to use them as a part of the song structure

Hello @talkingsmall and @snuff4,

Thank you very much for your great feedback. We really appreciate you offering this perspective early in the beta period of iOS 16.

You are correct that these properties are not currently exposed in MusicKit's Song.

I also agree with your general breakdown of these properties: exposing these properties doesn't have the same level of user impact, and the first set of properties should definitely be considered before any more advanced properties.

We'll definitely investigate this.

Best regards,

Accepted Answer

Hello @talkingsmall and @snuff4,

We made a number of important improvements to the list of available properties for items retrieved from the music library. You can find those in iOS 16 Beta 3, which just we just released today.

For example, the Song type now includes the following attributes:

I hope you'll find this useful.

Best regards,

@JoeKun

This is fantastic news, and in my early testing these properties are working great. I have two quick questions for whenever you get a chance.

  1. The description of lastPlayedDate uses some specific phrasing that caught my eye: "The date when the user last played the song on this device." Does it really mean it will only show the date the item was played on that device, or will it report the last play time across any device linked to the user's iCloud Music Library, the way MPMediaItem's lastPlayedDate works?
  2. How is lastPlayedDate determined for the Album object? There are a handful of albums in my test library where none of the songs have play counts, last play times, or last skip times, but the MusicKit album itself has a value for this property.

Thanks!

Hello @talkingsmall,

Glad to hear that these properties are working well for you!

To answer your questions:

  1. The description of lastPlayedDate is correct and will represent the date the item was last played on the user's device.
  2. As for how the lastPlayedDate and playCount are determined for albums, these properties are updated when the entire album is specifically played and not necessarily updated when a song within an Album is played.

Hopefully that makes things clearer!

-David

Hello @JoeKun @david-apple,

Is it somehow possible to request libraryAddedDate in Apple Music API, for example using this API method?
https://developer.apple.com/documentation/applemusicapi/get_all_library_songs

Exposing library-related metadata on library Songs
 
 
Q