2

I am trying to update the title using MPNowPlayingInfoCenter. But what happens is when I skip the track it does not reflect it on the control panel.

Here is my code:

int newIndex = [(NSNumber *)(notification.userInfo)[DRNewTrackIndex] intValue];
    NSUInteger trackCount;
    if (self.station.sortOptionType == DRFilterPlaylistSortOptionTypeShuffle) {
        trackCount = _station.playlist.tracks.count;
    } else {
        trackCount = _station.playlist.filteredTracks.count;
    }
    if (newIndex >= 0 && newIndex < trackCount) {
        DRPlaylistTrackModel *track = (self.station.sortOptionType == DRFilterPlaylistSortOptionTypeShuffle)?(_station.playlist.tracks)[newIndex]:(_station.playlist.filteredTracks)[newIndex];

        NSDictionary *nowPlayingInfoDictionary = [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo;
        NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] initWithDictionary:nowPlayingInfoDictionary];

        DRDDLogVerbose(@"Setting nowPlayingInfo: (songName: %@, bandName: %@, albumName: %@)",
                       track.title, track.artist.name, track.album.name);

        NSString *title = [self titleForTrack:track];
        if (title.length > 0) {
            songInfo[MPMediaItemPropertyTitle] = title;
        }

        NSString *subTitle = [self subTitleForTrack:track];
        if (subTitle.length > 0) {
            songInfo[MPMediaItemPropertyAlbumTitle] = subTitle;
        }

        if (title.length > 0 || subTitle.length > 0) {
            [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:[songInfo copy]];
        } else {
            // if title and station name are both empty, clear out old info
            [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];
        }
    } else {
        // clear old info
        [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:nil];
    }

Also when I put the debug point near title and subtitle I can see the correct information that is to be displayed for next song. But when I see it on the phone it does not display the correct track info as it showed in the debug point. I don't know whats happening here. I also assure that the above is happening on main thread only.

Jaycee
  • 159
  • 6

0 Answers0