iosobjective-cswiftios10mpnowplayinginfocenter

MPNowPlayingInfoCenter remote controls respond incorrectly in iOS 10


In iOS 10, the control center UI was reworked and since then, play/pause control buttons respond differently.

Content that cannot be paused should not change play/pause buttons in control center on every tap.

Before iOS 10, it was probably checking MPNowPlayingInfoPropertyPlaybackRate and if a content was not paused, it did not change the remote controls. In iOS 10, it changes every single time instantly ignoring MPNowPlayingInfoPropertyPlaybackRate.


Solution

  • The UIEvent delegate way of handling remote control events is no longer recommended for audio/video event handling. Instead, MPRemoteCommandCenter provides a selector-based interface to enable and disable buttons and remote control events, as well as the actions to handle those events.

    In the case where content should not be paused or resumed, you will have to explicitly set enabled property for each command to NO AND provide an action, even if it is just a dummy selector that does nothing, in order to disable the buttons in the Control Center properly:

    MPRemoteCommandCenter *commandCenter = [MPRemoteCommandCenter sharedCommandCenter];
    
    commandCenter.playCommand.enabled = NO;
    [commandCenter.playCommand addTarget:self action:@selector(playAudio)];
    
    commandCenter.pauseCommand.enabled = NO;
    [commandCenter.pauseCommand addTarget:self action:@selector(pauseAudio)];
    

    I elaborate on this further with an example from working with AVPlayer here.