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
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.
We can add filter that does not show iCloud items with
[mediaPicker setShowsCloudItems:NO];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With