嗨,我正在开发一个闹钟应用程序..我正在使用MPMediaPickerController类,使用它我可以选择和mp3文件,但不能在UINotification被调用时获得要播放的文件的路径。有没有人能提个建议??
谢谢
发布于 2011-05-06 18:14:24
不是给你路径,而是给你一个网址,它的格式是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 */
}https://stackoverflow.com/questions/5909639
复制相似问题