I have this code to play all songs in music library (added via iTunes and downloaded in library from Apple Music). I can not have just the songs. What am I doing wrong?
-(IBAction)playAllSongs:(id)sender {
MPMediaQuery *songsQuery = [MPMediaQuery songsQuery];
NSArray *songsArray = [songsQuery collections];
MPMediaItemCollection *items = [MPMediaItemCollection collectionWithItems:songsArray];
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController systemMusicPlayer];
[musicPlayer setQueueWithItemCollection:items];
}
I solved my self
MPMediaQuery *songsQuery = [MPMediaQuery songsQuery];
NSArray *songsArray = [songsQuery items];
MPMediaItemCollection *items = [MPMediaItemCollection collectionWithItems:songsArray];
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController systemMusicPlayer];
//[songsQuery addFilterPredicate:[MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithBool:NO] forProperty:MPMediaItemPropertyIsCloudItem]]; // for iTunes Match or Apple music to exclude or not songs not in the device
[musicPlayer setQueueWithItemCollection:items];