문제

i have this code for select and play an ipod songs

- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection{
[self dismissViewControllerAnimated:YES completion:nil];
[riproduttore setQueueWithItemCollection: mediaItemCollection];
[riproduttore play];

}

How i can load without pikerview a random song?

Ex. rnd 1 to 100, result = 66 and i can play song with index 66 in ipod library

도움이 되었습니까?

해결책

Try something like this:

MPMediaQuery* query = [MPMediaQuery songsQuery]; 
NSArray *songs = [query items];
MPMediaItem *randomTrack = [songs objectAtIndex:arc4random_uniform([songs count])];
// ... and then play with MPMediaPlayer, AVPlayer, etc.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top