Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMediaItemPropertyAssetURL returning null only for iPhone 5s

I have been using the following code to extract the asset url from the MPMediaItem object returned from the MPMediaItemPickerController so that I can copy music files from a users iPhone itunes music library to the documents folder for processing, but on iPhone 5s I always get a null value from the MPMediaItemPropertyAssetURL, but when I run the same code on iPhone 4 or iPhone 5 it works as it should returning a proper url.

- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {

    [self dismissViewControllerAnimated:YES completion:nil];

        if(mediaItemCollection){
           MPMediaItem *mediaItem = (MPMediaItem *)[mediaItemCollection.items objectAtIndex: 0];
           NSString *songTitle = [mediaItem valueForProperty: MPMediaItemPropertyTitle];
           NSLog(@"songtitle: %@", songTitle);
           NSURL *assetURL = [mediaItem valueForProperty: MPMediaItemPropertyAssetURL];
           NSLog(@"%@", assetURL);
        }

}

I have tried removing arm64 from valid architectures and only building for armv7 and armv7s, but that didn't fix this problem.

Does anyone know why this is happening and how I can fix it or if there is a workaround I can use? I need to be able to copy music from the iPhone's music library to the documents folder so that I can process the music properly for a dj application.

Thanks

like image 361
Greg Ellis Avatar asked Jan 17 '14 20:01

Greg Ellis


2 Answers

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. As much as I don't like answering my own question I took Jeroen's advice so that it can hopefully help others.

like image 73
Greg Ellis Avatar answered Nov 15 '22 13:11

Greg Ellis


We can add filter that does not show iCloud items with

[mediaPicker setShowsCloudItems:NO];
like image 42
Muhammed Tanriverdi Avatar answered Nov 15 '22 14:11

Muhammed Tanriverdi