How to show/hide Now Playing button on CPTabBarTemplate

I'm working on adding CarPlay support to an audio app and I'd like to mimic the behavior of the Apple Music app on launch.

Forgive me, but I think using Gherkin syntax here will help to best describe the desired behavior:

  • GIVEN the Apple Music app is in a cold state (not launched or in memory)
    • AND another audio app is actively playing audio
  • WHEN I launch the Apple Music app from CarPlay
  • THEN the Now Playing template is shown via a push
    • AND the appropriate Now Playing info is shown
    • AND the Now Playing button is shown on the tab bar
    • AND the actively playing audio from another audio app is NOT interrupted

The current behavior I see in my own app is that I can push on the Now Playing template and fill out the MPNowPlayingInfoCenter's info dictionary, but it won't render the info or show the Now Playing button on the tab bar until I start playing audio.

Also, is there a way to hide the Now Playing button after the queue of content has finished playing? I'm able to pop the Now Playing template, but the Now Playing button is still present and tapping it will navigate the user to the now blank Now Playing template.

Answered by Frameworks Engineer in 828208022

Hi,

The system automatically shows the now playing button in the tab bar and nav bar when your app becomes the now playing app, and hides the button when another app starts playing audio. You are correct that, in order for the now playing button to show AND for now playing to populate with metadata, your app must start playing audio.

In general, if your app is playing audio at the time when it's launched on the car screen, it's a best practice for your app to present its root template (e.g. a tab bar template) and then immediately push the now playing template on top. This is also done on behalf of your app if the user launches your app by way of the system 'Now Playing' icon on the CarPlay home screen.

Also, is there a way to hide the Now Playing button after the queue of content has finished playing? I'm able to pop the Now Playing template, but the Now Playing button is still present and tapping it will navigate the user to the now blank Now Playing template.

Not currently, but this sounds like a great enhancement request to file!

Accepted Answer

Hi,

The system automatically shows the now playing button in the tab bar and nav bar when your app becomes the now playing app, and hides the button when another app starts playing audio. You are correct that, in order for the now playing button to show AND for now playing to populate with metadata, your app must start playing audio.

In general, if your app is playing audio at the time when it's launched on the car screen, it's a best practice for your app to present its root template (e.g. a tab bar template) and then immediately push the now playing template on top. This is also done on behalf of your app if the user launches your app by way of the system 'Now Playing' icon on the CarPlay home screen.

Also, is there a way to hide the Now Playing button after the queue of content has finished playing? I'm able to pop the Now Playing template, but the Now Playing button is still present and tapping it will navigate the user to the now blank Now Playing template.

Not currently, but this sounds like a great enhancement request to file!

How to show/hide Now Playing button on CPTabBarTemplate
 
 
Q