3

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.

Jakub Truhlář
  • 20,070
  • 9
  • 74
  • 84
  • Can you clarify your question? Are you saying that for content that cannot pause, tapping on the pause button will change the button state but not pause the content? – JAL Sep 16 '16 at 14:00
  • Indeed. But it does not matter when and if the content can pause. E.g. If I completely ignore `remoteControlReceivedWithEvent` callback the button changes anyway now. – Jakub Truhlář Sep 16 '16 at 15:06
  • I would strongly discourage use of the old `UIEvent` delegate and switch to [`MPRemoteCommandCenter`](https://developer.apple.com/reference/mediaplayer/mpremotecommandcenter). See if my answer [here](http://stackoverflow.com/a/33161774/2415822) helps you. – JAL Sep 16 '16 at 15:08
  • 1
    Thank you, you pointed me in the right direction. I upvoted your original answer and at least post one here, if you do not mind. – Jakub Truhlář Sep 16 '16 at 17:28
  • No problem, glad your question was resolved! – JAL Sep 16 '16 at 17:29
  • I've added an additional answer that goes a little bit more in-depth to help future visitors to your question. – JAL Sep 16 '16 at 19:02
  • I have similar issue on iOS 10, where the pause/playback is not updated according to the state of MPNowPlayingInfoPropertyPlaybackRate. If I set the playrate to 0 (thus making the player pause) and then lock the screen, iOS10 still shows the "pause" symbol - even though the playback is actually on pause and it should instead show the "play" symbol to resume playback. Using MPNowPlayingInfoPropertyPlaybackRate to toggle pause/play is working fine on iOS 7-9. #ThanksApple Does anyone knows a workaround? :) – holm50 Dec 05 '16 at 10:52

1 Answers1

5

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.

Community
  • 1
  • 1
JAL
  • 41,701
  • 23
  • 172
  • 300
  • 1
    But even using the commandCenter to define which buttons to show, and which selectors to bind to the buttons, the commandCenter-buttons is still not updated when MPNowPlayingInfoPropertyPlaybackRate is changed. E.g. MPNowPlayingInfoPropertyPlaybackRate = 0 results in paused playback (and a "play" icon on lockscreen) on iOS 7-9; however, not on iOS10. – holm50 Dec 05 '16 at 10:53