4
votes

I am working on a project where I need to play songs from iTunes Library in AVPlayer. For that, I am taking URL "ipod-library://item/item.mp3?id=1577682869916034242" of selected songs from iTunes Library and playing same in AVPlayer. Almost all songs get play, but for few songs MPMediaItemPropertyAssetURL returns nil URL. Also receive following error

-[AVAssetReader initWithAsset:error:] invalid parameter not satisfying: asset != ((void *)0)

Any suggestion on this? and why I am getting nil value from

MPMediaItemPropertyAssetURL

Also any idea how to stream or convert DRM Protected Media track into NSData?. Please advice.

3
You can refer this stackoverflow.com/questions/5571036/…. I think you should check the url get from MPMediaItemPropertyAssetURL NSURL *assetURL = [item valueForProperty:MPMediaItemPropertyAssetURL]; if (assetURL && assetURL.aboluteString.length > 0) ...Proton
@DungProton I can check this. But I want to know the reason, why it is nil. What if I want to play that song?Sanchit Paurush
stackoverflow.com/questions/21195064/… ? Is it because it's in the cloud?Larme
It's DRM-protected media track (Digital rights management) ? You can check it by avItem.asset.hasProtectedContentProton
[mediaPicker setShowsCloudItems:NO]; try thisJagveer Singh

3 Answers

2
votes

MPMediaItemPropertyAssetURL can 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(@"DRM protected or not downloaded locally");
    }
0
votes

I found out that the problem was the song I was trying to get the MPMediaItemPropertyAssetURL property for was actually not on my device. It was listed in the media library, but was actually still in iCloud. Once I downloaded the song to my device then the problem was solved.

0
votes

Leaving this answer for other people like me.

Even though the music is on downloaded on the device, if it is DRM protected, MPMediaItem.value(forProperty: MPMediaItemPropertyAssetURL) will return nil as mentioned in the comment.

My app kept crashing and I confirmed this with my beta tester.

It seems like MPMusicPlayerController still supports playback so according to this answer.