The Issue About Using MPChangeRepeatModeCommand

Apple’s MediaPlayer framework has two APIs in iOS 10 to let you control your player’s repeat mode (to repeat a song, or a list, and so on) and shuffle mode (sequential or shuffle play) with CarPlay. They are MPChangeRepeatModeCommand and MPChangeShuffleModeCommand.

We tried to integrate these two APIs into our product, KKBOX’s audio app on iOS, but then we removed them, since they are conflicting with some popular in-car system.

If you read Apple’s document, you could find that Apple says that these APIs are available since iOS 8. But actually they are public since iOS 10 (See Apple’s iOS 10 API Changes). To use these two APIs is just like using all other commands of MPRemoteCommandCenter, such as play (MPRemoteCommand) and pause (MPRemoteCommand) commands. You can retrieve these commands from MPRemoteCommandCenter’ shared instance, and then call “addTarget:action:” selector upon them to specify what you would like to do when you receive these commands from users.

In addition, both of MPChangeRepeatModeCommand and MPChangeShuffleModeCommand has a property whose name is “currentRepeatType” that let you know about current repeat type or shuffle type.

If you implement these APIs, you can see there are two buttons appear in CarPlay’s Now Playing view.

CarPlay with Repeat Type and Shuffle Type

We supposed that these APIs are for CarPlay only, but things that we did not expect happened. If you connect your iPhone to some in-car system, such as Pioneers’ DEH, DEX and MVH series, we may receive these commands without any user inputs. A user may be confused and wonder why the shuffle mode is changes when he or she connect his or her device on the USB cable, when he or she prepares to drive a car.

These APIs are not well documented. We guess that there is a long existing software layer laying between iOS apps and in-car systems on iOS. When a non-CarPlay car system connects to an iPhone, the software layer lets the car system to identify it as an iPod, and bridges all the commands to audio apps, thus the car systems are able to interact with apps as an iPod. The ability to receive commands to change repeat and shuffle mode already exist for years, and the vendors of car systems may think they should send a command to reset “iPods” just when the connection is established.

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

This entry was posted in Code, iOS and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *