MPMediaItemPropertyAssetURL returns null for two possible reason.
- The music is not downloaded to your device but added in music
library only.
- 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.
- MPMediaItemPropertyAssetURL is nil ?
- 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");
}