Hi, I would like to be able to create a playlist from my app or add songs to an existing selected playlist in the user music library, How can I do that ? Is there an API in MusicKit to do that?
The Shazam app is doing something similar with the My Shazam Songs playlist...
Thanks
Hello @aleroot,
In iOS 15 and aligned releases for other Apple platforms, MusicKit is focused on giving access to the Apple Music catalog.
For this reason, the easiest way to create a playlist and add songs to it is probably to use existing APIs in the MediaPlayer framework.
Specifically, you could use:
- MPMediaLibrary's getPlaylist(with:creationMetadata: ) to create a new playlist with a specific identifier, or retrieve that playlist if it has already been created;
- MPMediaPlaylist's addItem(withProductID: ) to add items to this playlist using the ID of a music item.
Furthermore, you can definitely use the new MusicKit framework alongside MediaPlayer framework. For example, if you have a MusicKit Song, you could pass song.id.rawValue
as the productID
parameter to the MPMediaPlaylist's addItem(withProductID: ).
I hope this helps.
Best regards,