我有这个代码用于选择和播放ipod歌曲
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection{
[self dismissViewControllerAnimated:YES completion:nil];
[riproduttore setQueueWithItemCollection: mediaItemCollection];
[riproduttore play];
}
如何在没有pikerview的情况下加载随机歌曲?
实施例。 rnd 1到100,result = 66,我可以在ipod库中播放索引为66的歌曲
答案 0 :(得分:0)
尝试这样的事情:
MPMediaQuery* query = [MPMediaQuery songsQuery];
NSArray *songs = [query items];
MPMediaItem *randomTrack = [songs objectAtIndex:arc4random_uniform([songs count])];
// ... and then play with MPMediaPlayer, AVPlayer, etc.