If you are playing the songs present in your iPod library then you can make use of MPMusicPlayerController
, this class contains bunch of property to change the states like shuffleMode
or repeatMode
.
If you are using AVAudioPlayer
add a receiver for notification AVPlayerItemDidPlayToEndTimeNotification
and inside the observer query your array arrAnand
to fetch the random mediaItem
Hope this helps you.
Edit :
Inside itemDidFinishPlaying
-(void)itemDidFinishPlaying
{
MPMediaItem *item = [arrAnand objectAtIndex:i];
NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];
if(player2)
{
[player2 release];
player2 = nil;
}
player2 = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[player2 play];
}
Note : where i is any random number (should be less than the [arrAnand count]).