最初に起動したときに、初めて実際に選択した曲が再生されない音楽プレーヤーで選択したアイテムが再生されない
何らかの理由で、音楽アプリで最後に再生された曲の再生がアプリから開始されます。私は選択した曲をそれに渡していても、すべてがコンソールにログインしています。
それから、すべて正常に動作し、アプリは選択した曲を再生します。
何が起こっているのかわかりません。
- (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);
}
}
}
setItemではなくskipToNextItemを試してみてください。 –
@johnelemansはあなたが '[musicPlayer setNowPlayingItem:rowItemSong];の代わりに' [musicPlayer skipToNextItem] 'のようなことを言っています+' [musicPlayer play]; '? – SRMR
はい、そういう意味です。 alexcuryloの答えは面白いです! –