您好 我正在制作一个闹钟应用程序.. 我正在使用MPMediaPickerController类,使用它我能够选择和mp3文件但是无法在调用UINotification时获取文件的路径。 任何人都可以提出建议...... ??
由于
答案 0 :(得分:2)
您没有获得路径,您将获得一个URL,其形式为AVFoundation应该理解它。我认为你永远不会找到路径的部分原因是保护DRM内容。无论如何,您的委托应该将返回的MPMediaItemCollection向下钻取到您想要的MPMediaItem,然后您可以使用valueForProperty
来获取合适的URL。
用于播放MPMediaPickerController中所选内容的示例代码(此处首次输入,如果我发现任何错误,请发表评论):
// delegate method, to receive the result of the MPMediaPickerController
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker
didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection
{
// use the first item in the collection
MPMediaItem *item = [[mediaItemCollection items] objectAtIndex:0];
// get the URL to the MP3
NSURL *URL = [item valueForProperty:MPMediaItemPropertyAssetURL];
// URL uses a proprietary scheme, but AVFoundation understands it, so...
AVAudioPlayer *player = [[AVAudioPlayer alloc]
initWithContentsOfURL:URL error:NULL];
[player play];
/* NB: player will leak. Do something more sensible in your code */
}