问题
How to convert the iPod library to NSData. The url is:
ipod-library://item/item.mp3?id=1258203422631791096
Getting error but, I can play the song by using AVPlayer.
NSURL *url = [curItem valueForProperty: MPMediaItemPropertyAssetURL];
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfFile:[url absoluteString] options:NSDataReadingMappedAlways error:&error];
NSLog(@"Error : %@",error);
The curItem is a MPMediaItem
Error Domain=NSCocoaErrorDomain Code=260 "The file “item.mp3?id=1258203422631791096” couldn’t be opened because there is no such file." UserInfo={NSFilePath=ipod-library://item/item.mp3?id=1258203422631791096, NSUnderlyingError=0x15ff23420 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
回答1:
You cannot access the media item URL directly, as it resides outside your application's sandbox.
You need to fetch the asset using AVAssetExportSession that saves it to an URL in your sandbox. You can get NSData from there – see this SO question iOS 6 issue Convert MPMediaItem to NSData
来源:https://stackoverflow.com/questions/36694233/ipod-library-path-to-nsdata