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.
Frage
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
Lösung
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.