【发布时间】:2016-07-09 12:36:19
【问题描述】:
在应用首次启动时,第一次选择任何歌曲时,应用从不播放实际选择的歌曲。
出于某种原因,该应用将开始播放上次在“音乐”应用中播放的歌曲。即使我将选定的歌曲传递给它,并且一切都在控制台中正常登录。
但此后一切正常,应用播放所选歌曲。
我不知道发生了什么,有什么想法吗?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"nowPlaying"]){
// send to now playing
NSUInteger selectedSection = [[self.tableView indexPathForSelectedRow] section];
NSUInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
NSArray *albumTracksArray = [self albumTracksForSegue:[[albumsArrayForTVC objectAtIndex:selectedSection] representativeItem]];
MPMediaItem *rowItemSong = [[albumTracksArray objectAtIndex:selectedIndex] representativeItem];
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController systemMusicPlayer];
[musicPlayer setQueueWithItemCollection:[MPMediaItemCollection collectionWithItems:albumTracksArray]];
if ([musicPlayer nowPlayingItem] == rowItemSong) {
// Nothing
NSLog(@"These songs are equivalent: %@", [musicPlayer nowPlayingItem]);
[musicPlayer setNowPlayingItem:rowItemSong];
[musicPlayer play];
NSLog(@"Row Item Song Same: %@", rowItemSong);
} else {
[musicPlayer setNowPlayingItem:rowItemSong];
[musicPlayer play];
NSLog(@"Row Item Song Different: %@", rowItemSong);
}
}
}
【问题讨论】:
-
尝试使用 skipToNextItem 而不是 setItem 并播放。
-
@johnelemans 你是在说
[musicPlayer skipToNextItem]而不是[musicPlayer setNowPlayingItem:rowItemSong];+[musicPlayer play];? -
是的,我就是这个意思。 alexcurylo 的回答很有趣!
-
@johnelemans 太棒了,非常感谢!
-
@johnelemans 只是想知道,这种方式总是会跳到下一首歌吗?因为在我最初的问题中,奇怪的边缘情况只发生在应用程序第一次运行时,所以我不希望它总是跳到下一首歌曲,因为它不会播放被选中的歌曲。跨度>
标签: ios objective-c mpmusicplayercontroller