Question

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

Was it helpful?

Solution

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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top