iPod Library path to NSData
Asked Answered
H

1

0

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"}}
Hazy answered 18/4, 2016 at 12:37 Comment(1)
You have to use AVAssetExportSession. Only AVFondation stuff should be allowed to open files with "ipod-library".Camass
E
3

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

Envenom answered 18/4, 2016 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.