首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ios音乐播放器

ios音乐播放器
EN

Stack Overflow用户
提问于 2011-05-06 17:48:54
回答 1查看 1.7K关注 0票数 0

嗨,我正在开发一个闹钟应用程序..我正在使用MPMediaPickerController类,使用它我可以选择和mp3文件,但不能在UINotification被调用时获得要播放的文件的路径。有没有人能提个建议??

谢谢

EN

回答 1

Stack Overflow用户

发布于 2011-05-06 18:14:24

不是给你路径,而是给你一个网址,它的格式是AVFoundation应该理解的。我认为你永远得不到路径的部分原因是为了保护DRM内容。无论如何,你的代理应该将返回的MPMediaItemCollection下钻到你想要的MPMediaItem,然后你可以使用valueForProperty来获得合适的URL。

立即播放MPMediaPickerController中所选内容的示例代码(这里是第一次键入,如果我犯了任何错误,请评论):

代码语言:javascript
复制
// 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 */
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5909639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档