Apple Music API - Create a Playlist

I am studying the Apple Music API to find out what features I can expect in an iOS app. I created a small test application that gets permission from the user and displays the playlists that I have (and songs) on NSLog.

MPMediaQuery *myPlaylistsQuery = [MPMediaQuery playlistsQuery];
            [myPlaylistsQuery setGroupingType:MPMediaGroupingPlaylist];
            NSArray *playlists = [myPlaylistsQuery collections];

            for (MPMediaPlaylist *playlist in playlists) {
                NSLog (@"%@", [playlist valueForProperty: MPMediaPlaylistPropertyName]);

                NSArray *songs = [playlist items];

                for (MPMediaItem *song in songs) {
                    NSString *songTitle =
                    [song valueForProperty: MPMediaItemPropertyTitle];
                    NSLog (@"\t\t%@", songTitle);
                }
            }

From this, I was able to deduce the following (but I'm not 100% sure):

  • playlist (basic information: name, identifier) ​​is stored locally on the device
  • songs from the playlist are also pulled out of the local storage, but if the playlist has not been downloaded to the device, it leaves Apple to grab the list of songs.

So far so good. I want to know:

  • Is there a way to create a playlist from my application (via the API)?

, MPMediaPlaylist addItem add, .

: https://affiliate.itunes.apple.com/resources/blog/apple-music-api-faq/

API Apple Music?

. API .

+4
1

. , .

NSUUID *uuid = [NSUUID UUID]; //uuid for the playlist
[[MPMediaLibrary defaultMediaLibrary] getPlaylistWithUUID:uuid creationMetadata:[[MPMediaPlaylistCreationMetadata alloc] initWithName:@"YOUR PLAYLIST NAME"] completionHandler:^(MPMediaPlaylist * _Nullable playlist, NSError * _Nullable error) {
    NSLog(@"%@", error);

    if (!error) {
        NSLog(@"All ok let do some stuff with the playlist!"); 
    }
}];

Apple API !

+4

Source: https://habr.com/ru/post/1670948/


All Articles