monstercoo
monstercoo

Reputation: 93

NULL MPMediaitemPropertyAssetURL

Using MPMediaQuery and then getting the MPMediaitemPropertyAssetURL from the song results sometimes returns null (and by sometimes I mean in this case, 1/3 of the users song library).

Does anyone know what causes this? I'm assuming that this is due to some sort of DRM, but it isn't documented anywhere.

Upvotes: 2

Views: 3813

Answers (2)

emraz
emraz

Reputation: 1613

MPMediaItemPropertyAssetURL returns null for two possible reason.

  1. The music is not downloaded to your device but added in music library only.
  2. The music is loaded but its DRM-protected.

DRM-protected asset is not possible to play using AVPlayer, its only able to play using MPMusicPlayer. So you must need to check two things before proceed with AVPlayer.

  1. MPMediaItemPropertyAssetURL is nil ?
  2. MPMediaItem is protected ?

Please see the code below….

MPMediaItem *theChosenSong = [[mediaItemCollection items] firstObject];
NSURL *assetURL = [theChosenSong valueForProperty:MPMediaItemPropertyAssetURL];

        if(assetURL) {
            BOOL bIsProtected = theChosenSong.protectedAsset;
            if(!bIsProtected) {
                // Do whatever you want to do
                NSLog(@"Its not protected");
           }
            else {
                NSLog(@"Its DRM protected");
            }
        }
        else {
                NSLog(@"Its DRM protected");
        }

Upvotes: 0

ıɾuǝʞ
ıɾuǝʞ

Reputation: 2849

This answer can respond to your question : https://stackoverflow.com/a/6401317/536308

Upvotes: 1

Related Questions