我有这个代码来播放音乐库中的所有歌曲(通过iTunes添加并从Apple Music下载到库中)。 我不能只有歌曲。我做错了什么?
-(IBAction)playAllSongs:(id)sender {
MPMediaQuery *songsQuery = [MPMediaQuery songsQuery];
NSArray *songsArray = [songsQuery collections];
MPMediaItemCollection *items = [MPMediaItemCollection collectionWithItems:songsArray];
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController systemMusicPlayer];
[musicPlayer setQueueWithItemCollection:items];
}
答案 0 :(得分:1)
上述答案有效,但这是一种迂回的方式。 一种更简单的方法:
MPMediaQuery *songs = [MPMediaQuery songsQuery];
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController systemMusicPlayer];
[musicPlayer setQueueWithQuery:songs]
答案 1 :(得分:0)
我解决了自己
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];