1

However I implement the proper MPRemoteCommandCenter functions, the playback buttons are not responsive at all in carplay app.

(It works correctly with CarPlay before iOS 14, using MPPlayableContentManager)

Non of the MPRemoteCommandCenter callbacks are being called.

What could be the reason?

The code where I set up remote command center:

func setupRemoteCommandCenterTargets() {                        
        
        let commandCenter = MPRemoteCommandCenter.shared()
                                                
        commandCenter.playCommand.isEnabled = true
        commandCenter.playCommand.addTarget {event in
            
            //myPlayer.play()
            return .success
        }
        
        commandCenter.pauseCommand.isEnabled = true
        commandCenter.pauseCommand.addTarget {event in
            
            //myPlayer.pause()
            return .success
        }
                
        commandCenter.nextTrackCommand.isEnabled = true
        commandCenter.nextTrackCommand.addTarget {event in
            //myPlayer.next()
            return .success
        }
                
        commandCenter.previousTrackCommand.isEnabled = true
        commandCenter.previousTrackCommand.addTarget {event in
            //myPlayer.prev()
            return .success
        }
    }

Buttons seem to be disabled on head unit and not any from the MPRemoteCommandCenter callback is being called.

  • Can you test on a real device? The simulator is pretty unstable (especially when it comes to MPRemoteCommands). Also, have to tried adding a handler to the `togglePlayPauseCommand`? And check if your `setupRemoteCommandCenterTargets` is called even when the app is run in the background (only started via CarPlay) – fruitcoder Oct 26 '21 at 13:16
  • Buttons were disabled by using a head unit in a real car also. I found the reason: MPNowPlayingInfoCenter.default().nowPlayingInfo[MPNowPlayingInfoPropertyIsLiveStream] = true made seek back and forward controls disabled. By setting MPNowPlayingInfoCenter.default().nowPlayingInfo[MPNowPlayingInfoPropertyIsLiveStream] = false the player controls are enabled and they are working. – Károly Horváth-Dori Oct 27 '21 at 14:50
  • Oh, since it said radio I thought it is a livestream so I didn‘t mentioned it. Play/Pause should also work when MPNowPlayingInfoPropertyIsLiveStream is true – fruitcoder Oct 28 '21 at 06:51
  • 1
    Play/Pause commands do work with MPNowPlayingInfoPropertyIsLiveStream = true on phone and using AirPlay. But it doesn't work when I'm connected to the car's head unit using CarPlay. – Károly Horváth-Dori Oct 29 '21 at 11:27
  • Can you try enabling the stop command? I think when it's a livestream you should enable the stop command and/or the toggleCommand. And always try on the real device (even though it might work on the simulator sometimes) – fruitcoder Dec 01 '21 at 08:45

1 Answers1

0

I know this question is old but I came across the same problem recently. What I deduced is that when MPNowPlayingInfoPropertyIsLiveStream is set to true, then the audio is considered a live stream and, in that case, you shouldn't use the pause button from the control center but the stop button instead.

In fact, if you implement the stop command:

commandCenter.stopCommand.addTarget { [unowned self] event in
    // myPlayer.pause()
    return .success
}

The control center changes on the iPhone too, not just on CarPlay, and the button for live streams become "stop".

I have no idea why on CarPlay the button is "stop" by default instead of pause, but this will fix your issue.

Rexam
  • 823
  • 4
  • 23
  • 42