MPNowPlayingInfoCenter nowPlayingInfo not updating at end of track

For background info update, my colleague suggests some implementations are necessary. Maybe you can check and verify some of these requirements in your view controller:

    //1: Set true for canBecomeFirstResponder func
    override func canBecomeFirstResponder() -> Bool {
        return true
    }

    //2: Set view controller becomeFirstResponder & allow to receive remote control events
    override func viewDidLoad() {
        super.viewDidLoad()
        self.becomeFirstResponder()
        UIApplication.sharedApplication().beginReceivingRemoteControlEvents()
        ....
    }

    //3: Implement actions after did receive events from remote control
    override func remoteControlReceivedWithEvent(event: UIEvent?) {
        guard let event = event else {
            return
        }
        switch event.subtype {
        case .RemoteControlPlay:
            ....
            break
        case .RemoteControlPause:
            ....
            break
        case .RemoteControlStop:
            ....
            break
        default:
            print("default action")
        }
    }

The problem is that nowPlayingInfo is updated in two places at the same time when the track automatically changes: in the setTrackNumber method which is triggered by AVPlayerItemDidPlayToEndTimeNotification and in the playerTimeJumped method which is triggered by AVPlayerItemTimeJumpedNotification.

This causes a race condition. More details are provided by an Apple staff member here.

The problem can be solved by keeping a local nowPlayingInfo dictionary that gets updated as needed and always setting MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo from that instead of setting individual values.