i am getting the null values ,whenever i am using MPMediaItemCollection convert MPMediaItemPropertyAssetURL to data?

here my code

MPMediaItemCollection *collection=[allAlbumsArray objectAtIndex:indexPath.row];
MPMediaItem *item = [collection representativeItem];

NSLog(@" songs titles_str url is===>%@",[item valueForProperty:MPMediaItemPropertyAssetURL]);

NSLog(@"class type is %@",[[item valueForProperty:MPMediaItemPropertyAssetURL] class]);

self.songData=[NSData dataWithContentsOfURL:[item valueForProperty:MPMediaItemPropertyAssetURL]];

NSLog(@"original data is %@",self.songData);

here i am getting url for song ipod-library://item/item.mp3?id=-9207595762773025867

but when i convert into data i getting null value Thanks for advance.

1

There are 1 best solutions below

4
On BEST ANSWER

The problem here is that the URL has a custom scheme, ipod-library, which can only be used with AVFoundation methods, for example AVAsset objects.

The MPMediaItem Class Reference says this about MPMediaItemPropertyAssetURL:

MPMediaItemPropertyAssetURL

A URL pointing to the media item, from which an AVAsset object (or other URL-based AV Foundation object) can be created, with any options as desired. Value is an NSURL object.

The URL has the custom scheme of ipod-library. For example, a URL might look like this:

ipod-library://item/item.m4a?id=12345

Usage of the URL outside of the AV Foundation framework is not supported.