ios音乐播放器

问题描述:

嗨 我正在使用闹钟应用程序.. 我正在使用MPMediaPickerController类,使用它我能够选择和mp3文件但无法获取播放文件时的路径被调用。 任何人都可以提出一些建议.. ??ios音乐播放器

感谢

+0

把一些代码的朋友......让我们可以发现哪里是你的问题.. – Krishnabhadra 2011-05-06 10:01:00

+0

- (空)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection { \t \t \t musicPlayer = [MPMusicPlayerController应用licationMusicPlayer]; \t [musicPlayer setQueueWithItemCollection:mediaItemCollection]; \t [musicPlayer play]; MPMediaItem * item = [[mediaItemCollection items] objectAtIndex:0];或者使用MPMediaItem * item = [[mediaItemCollection items] objectAtIndex:0]; \t url_song = [item valueForProperty:MPMediaItemPropertyAssetURL]; (@“歌曲的路径是%@”,url_song); 我想要选择的歌曲的URL传递给UIlocalNotification,以便它应该发挥whenevr通知来... – Abhinandan 2011-05-09 04:47:46

你不给出的路径,你获得一个网址,在这样的形式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 */ 
} 
+0

非常感谢您的响应..我想澄清,我可以传递此网址UILocalNotification选择歌曲名称,如... notif1.soundName = url_song; – Abhinandan 2011-05-09 04:35:34

+0

嗨 有人会帮助我,我卡住了.. – Abhinandan 2011-05-09 09:15:10

+0

我不认为你可以使用soundName属性来播放选定的MP3。在属性描述中,它表示它只能播放30秒内位于应用程序包中的某个媒体文件。我不知道如何制作一个MP3闹钟,我现在也在搜索它。 – 2012-04-18 06:58:33