IPod Library Path to NSData

How to convert iPod library to NSData. Url:

ipod-library://item/item.mp3?id=1258203422631791096 

Getting error, but I can play the song using AVPlayer.

  NSURL *url = [curItem valueForProperty: MPMediaItemPropertyAssetURL]; NSError *error = nil; NSData *data = [NSData dataWithContentsOfFile:[url absoluteString] options:NSDataReadingMappedAlways error:&error]; NSLog(@"Error : %@",error); 

curItem is 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"}} 
0
source share
1 answer

You cannot access the URL of the media content directly, as it is located outside the application sandbox.

You need to get the asset using AVAssetExportSession, which saves it to a URL in your sandbox. You can get NSData from here - see this SO iOS 6 question . Convert MPMediaItem to NSData

+2
source

Source: https://habr.com/ru/post/947658/


All Articles