MPMusicPlayerController setQueue 和 noPlayingItem 默认为索引 0
MPMusicPlayerController setQueue and noPlayingItem defaults to index 0
当我尝试更改 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
停止播放器而不是暂停播放器解决了问题。
当我尝试更改 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
停止播放器而不是暂停播放器解决了问题。