当我尝试改变MPMusicPlayerController的队列并设置nowPlayingItem时,播放器总是转到队列中的第一个项目。文档说,如果我想设置队列中的当前位置,我应该将nowPlayingItem设置为队列中的MPMediaItem。我做错了什么吗?
MPMusicPlayerController *player = [MPMusicPlayerController systemMusicPlayer];
[player setRepeatMode:MPMusicRepeatModeNone];
[player setShuffleMode:MPMusicShuffleModeOff];
[player pause];
MPMediaItemCollection *collection = [MPMediaItemCollection collectionWithItems:[[HMFAudioManager sharedManager] playlist]];
[player setQueueWithItemCollection:collection];
MPMediaItem *selectedItem = collection.items[indexPath.row];
NSLog(@"selected item - %@",selectedItem.title);
NSLog(@"manager's current now playing item - %@",[[HMFAudioManager sharedManager] nowPlayingItem].title);
[[HMFAudioManager sharedManager] setNowPlayingItem:collection.items[indexPath.row]];
NSLog(@"manager's new now playing item - %@",[[HMFAudioManager sharedManager] nowPlayingItem].title);
player.nowPlayingItem = collection.items[indexPath.row];
player.currentPlaybackTime = [collection.items[indexPath.row] bookmarkTime];
[player play];
NSLog(@"player's now playing - %@",player.nowPlayingItem.title);
NSLog(@"manager's new now playing item - %@",selectedItem.title);
[self dismissViewControllerAnimated:YES completion:nil];
日志——2015-08-07 16:51:42.003 Undulib[1986:487940] selected item - Star Wars: The Empire Strikes Back
2015-08-07 16:51:42.004 Undulib[1986:487940] manager's current now playing item - Star Wars: A New Hope
2015-08-07 16:51:42.005 Undulib[1986:487940] manager's new now playing item - Star Wars: The Empire Strikes Back
2015-08-07 16:51:42.238 Undulib[1986:487940] player's now playing - Star Wars: A New Hope
2015-08-07 16:51:42.238 Undulib[1986:487940] manager's new now playing item - Star Wars: The Empire Strikes Back
停止播放而不是暂停解决了这个问题。