Converting MusicKit's Song (MusicItem) to MPMediaItem!

Hi ,

I have a usecase where I need to add multiple songs to apple music playlists. I am using MPMediaplaylist.addItem(withProductID: ) function to add a single song to the playlist. Is there a way to convert the song to MPMediaItem so that I can use MPMediaplaylist.add([MPMediaItem]) to add multiple songs to the playlist?

Regards

Answered by Frameworks Engineer in 718690022

Hello @Nitishbll,

There is no API to convert a Song from MusicKit into an MPMediaItem.

However, in iOS 16 and aligned releases, you can add songs to a Playlist using MusicKit directly, with MusicLibrary's add(_:to:) method.

If you want to add multiple songs at a time to that Playlist, and assuming it's a playlist you created in your app using one of the new createPlaylist(…) methods in MusicLibrary, then you can also use the edit(…) method, which allows you to edit the playlist, including replacing its entries, which offers a lot more power than just appending an item to the end of the playlist.

I hope this helps.

Best regards,

Accepted Answer

Hello @Nitishbll,

There is no API to convert a Song from MusicKit into an MPMediaItem.

However, in iOS 16 and aligned releases, you can add songs to a Playlist using MusicKit directly, with MusicLibrary's add(_:to:) method.

If you want to add multiple songs at a time to that Playlist, and assuming it's a playlist you created in your app using one of the new createPlaylist(…) methods in MusicLibrary, then you can also use the edit(…) method, which allows you to edit the playlist, including replacing its entries, which offers a lot more power than just appending an item to the end of the playlist.

I hope this helps.

Best regards,

Got It,

Thanks for the superfast reply

Warm Regards Nitish Kumar

Converting MusicKit's Song (MusicItem) to MPMediaItem!
 
 
Q