Objective C: Getting MPMediaItem 'Favorite' property
Asked Answered
B

1

1

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.

enter image description here

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?

Blayze answered 16/2, 2016 at 21:49 Comment(0)
S
5

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

Snowberry answered 8/6, 2018 at 23:31 Comment(3)
I would recommend adding more information to your answer, such as the request/response detailsBlayze
Well Apple Music API has a whole bunch of documents on how to build a request and analysis responses. If the asker really decides to use Apple Music API for the task, I would love to provide more information on to them, but I believe that will be another topic. There are too many things to do before request can be built.Snowberry
Goodness thanks @AMGuru. I was looking for this for ages!Spinneret

© 2022 - 2024 — McMap. All rights reserved.