On initial startup of the app, the first time any song is selected, the app never plays the actual song selected.
The app will start playing whatever song was last playing in the Music app for some reason. Even though I'm passing the selected song to it and everything is logging in the console fine.
But then everything works fine from then on, and the app plays the song selected.
I have no idea what is going on though, any ideas?
- (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);
}
}
}