Objective C: Getting MPMediaItem 'Favorite' property

♀尐吖头ヾ 提交于 2019-12-05 05:47:35

问题


I was looking at Apple's documentation, and I cannot seem to find a way to get whether or not an MPMediaItem is a 'favorite' track or not. See screenshot below, with the pink heart.

How can one get this property? I know since it's a new feature, it's availability would be limited to iOS 8.4 or later.

Here's some code I'm using to get other properties from MPMediaItems, via the music picker:

- (void) processMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
            //iterate through selected songs
            if (mediaItemCollection) {
                NSArray *allSelectedSongs = [mediaItemCollection items];

                for(MPMediaItem *song in allSelectedSongs)
                {
                    NSURL *songURL = [song valueForProperty:MPMediaItemPropertyAssetURL];
                    NSNumber *ident = [song valueForProperty:MPMediaEntityPropertyPersistentID];
                    NSString *identString = [BukketHelper convertULLToNSString:ident];
                    NSNumber *isCloud = [song valueForProperty:MPMediaItemPropertyIsCloudItem];
                }

 //do other stuff here
}

Anyone have ideas?


回答1:


You have to use Apple Music API to get or set users's Like/Dislike to a song like this:

GET https://api.music.apple.com/v1/me/ratings/songs/{id}

From: Apple Docs link



来源:https://stackoverflow.com/questions/35443693/objective-c-getting-mpmediaitem-favorite-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!