I have a playlist screen in my app where users can choose any song in the playlist and the app will start playing from that song.
I use the following code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MPMediaItem *selectedSong = [currentQueue.items objectAtIndex:indexPath.row];
[audioCoordinator.musicController setNowPlayingItem: selectedSong];
[audioCoordinator playAllSound];
}
It works well with a playlist with all distinct songs, but since this playlist allows duplicate songs, here comes the problem. For this playlist:
- Long Long Ago
- My December
- Long Long Ago
When the user taps on the 3rd song, the app would play the 1st song, since they have identical names, this is not the correct behavior.
How can we provide the setNowPlayingItem function of MPMusicPlayerController an index so that it can start playing from there?