Search code examples
objective-cios5ios4mpmediaitemmpmediapickercontroller

URL to MPMediaItem


I have a simple question but I can't find the right answer. I have a song url saved to my database in a path like this.

aSound.path = [[item valueForProperty: MPMediaItemPropertyAssetURL] absoluteString];

How to convert back to a MPMediaItem object which has songname artist and artwork?

Is it possible?


Solution

  • Saving:

        NSNumber* persistentID = 
    [mediaItem valueForProperty:MPMediaItemPropertyPersistentID];
    

    Loading:

                MPMediaPropertyPredicate * predicate = 
                  [MPMediaPropertyPredicate 
                    predicateWithValue:persistentID 
                           forProperty:MPMediaItemPropertyPersistentID];
    

    Another example: NSNumber for MPMediaItemPropertyPersistentID to NSString and back again

    Note song URLs are are unreliable because any DRM song returns a null url