2011-05-06 348 views
1

嗨 我正在使用鬧鐘應用程序.. 我正在使用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

回答

2

你不給出的路徑,你獲得一個網址,在這樣的形式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