Library到NSData的路径

Library到NSData的路径

本文介绍了iPod Library到NSData的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将iPod库转换为NSData.网址是:

How to convert the iPod library to NSData.The url is:

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

遇到错误,但是我可以使用AVPlayer播放歌曲.

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);

curItem是MPMediaItem

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"}}

推荐答案

您不能直接访问媒体项URL,因为它位于应用程序的沙箱外部.

You cannot access the media item URL directly, as it resides outside your application's sandbox.

您需要使用AVAssetExportSession来获取资产,并将其保存到沙箱中的URL.您可以从那里获取NSData –请参阅此问题 iOS 6问题将MPMediaItem转换为NSData

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

这篇关于iPod Library到NSData的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 12:33