在我的應用程序中,我必須製作音樂庫。因此,我必須從音樂庫中獲取歌曲。我完成了,直到這再見。如何從音樂庫獲取歌曲列表後播放音樂文件?
Test_MusicLibraryAppDelegate *appDeleg = (Test_MusicLibraryAppDelegate *)[[UIApplication sharedApplication]delegate];
//NSMutableDictionary *musicList = [NSMutableDictionary dictionary];
MPMediaQuery *query = [[MPMediaQuery alloc] init];
[query addFilterPredicate:[MPMediaPropertyPredicate
predicateWithValue:[NSNumber numberWithInteger:(MPMediaTypeMusic)]
forProperty:MPMediaItemPropertyMediaType]];
for (MPMediaItem* item in [query items]) {
[appDeleg.arryMusic addObject:item];
}
NSLog(@"Count :: %d ",[appDeleg.arryMusic count]);
[query release];
比在表格視圖中顯示它。
當我有打歌所選指標i獲取歌曲的名稱,但不`噸知道怎麼玩那首歌,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Test_MusicLibraryAppDelegate *appDeleg = (Test_MusicLibraryAppDelegate *)[[UIApplication sharedApplication]delegate];
// MPMediaItem *song = [appDeleg.arryMusic objectAtIndex:indexPath.row];
NSURL *aURL = [appDeleg.arryMusic objectAtIndex:indexPath.row];
//[song valueForProperty:MPMediaItemPropertyAssetURL];
[[self avPlayer] replaceCurrentItemWithPlayerItem:
[AVPlayerItem playerItemWithURL:aURL]];
[avPlayer play];
}
,但我的聲音文件,玩不下去...
嘿任何一個知道這不是幫助我..
感謝 AJPatel
問題清楚地表明,用戶正在使用'AVPlayer'所以建議他改變使用'MPMusicPlayerController'是有點誤導,並沒有真正回答他的問題。 –
即使您的答案被接受,您爲什麼還沒有投票?你認爲這種可接受的行爲?對我來說,降低你的答案是完全合理的,因爲它不能真正幫助回答問題,但我選擇不回答。因爲我留下了評論,因此下調投票相當不成熟。 –