iPod Library path to NSData

喜欢而已 提交于 2019-12-12 02:53:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!