MPNowPlayingInfoCenter MPRemoteCommandCenter macOS, control center and media keys not working for Catalyst app

I have a Catalyst application that uses (as expected) MPNowPlayingInfoCenter to set the now playing info and MPRemoteCommandCenter to get the media events for play/pause/stop/favorite/etc.

The code is shared on iOS, tvOS and watchOS and it works correctly there. It seems not to work on macOS (app is compiled as a Catalyst application) on Big Sur (and Monterey, fwiw). Media keys on the keyboard starts the Music app, the music part of the control center do not show now playing info (nor the media controls there send messages to the app).

I seem to remember that it used to work in Catalina (at least the media key part) and for sure it used to work in a precedent version of the same app that used to be an UIKit one.

Is this a bug (worth a feedback to Apple) or something wrong on my side? I forgot some magic capability for macOS? App is sandboxed and uses hardened runtime, in case this is significant.

Thank you for any hint!

Answered by megatron1000 in 703271022

I've somewhat figured this out. I can get skip to work but I still haven't managed to get play/pause from the keyboard to work.

The thing that I was missing is on macOS you need to update the playing state on MPNowPlayingInfoCenter. It can't just infer it from the AVAudioSession like it does on other platforms.

.i.e. MPNowPlayingInfoCenter.default().playbackState = .playing

Since I started doing that my app shows up in 'Now Playing' and all the controls work fine there. I just can't figure out why play/pause on the keyboard still doesn't work.

        

Yes, I think a bug report would be an excellent idea. Please paste the bug number here.

I'm seeing this as well so was wondering if there was something else I had to do to add support for macOS. I only just started testing my app on the desktop, but I'm unable to control it with the media keys under Monterey 12.0.1.

Following this thread.

Accepted Answer

I've somewhat figured this out. I can get skip to work but I still haven't managed to get play/pause from the keyboard to work.

The thing that I was missing is on macOS you need to update the playing state on MPNowPlayingInfoCenter. It can't just infer it from the AVAudioSession like it does on other platforms.

.i.e. MPNowPlayingInfoCenter.default().playbackState = .playing

Since I started doing that my app shows up in 'Now Playing' and all the controls work fine there. I just can't figure out why play/pause on the keyboard still doesn't work.

        

This is still not resolved

MPNowPlayingInfoCenter MPRemoteCommandCenter macOS, control center and media keys not working for Catalyst app
 
 
Q