Display a Now Playing card

Stay organized with collections Save and categorize content based on your preferences.

TV apps must display a Now Playing card when playing media behind the launcher or in the background. This card allows users to return to the app that is currently playing media.

The Android framework displays a Now Playing card on the home screen when there is an active MediaSession. The card includes media metadata such as album art, title, and app icon. When the user selects the card, the system opens the app.

You can use the MediaSession class to implement the Now Playing card.

Figure 1. Display a Now Playing card when playing media in the background.

Display a Now Playing card

After you've integrated a media session, set the session to active, and requested audio focus, the Now Playing card appears.

Note: The Now Playing card will display only for a media session with the FLAG_HANDLES_TRANSPORT_CONTROLS flag set.

The card is removed from the launcher screen when a setActive(false) call deactivates the media session, or when another app initiates media playback. If playback is completely stopped and there is no active media, your app should deactivate the media session immediately. If playback is paused, your app should deactivate the media session after a delay, usually between 5 to 30 minutes.

Update the card

Whenever your app updates the playback state in the MediaSession, the Now Playing card updates to show the state of the current media. To learn how to do this, see Update the playback state.

Similarly, your app can update the MediaMetadata to provide information to the Now Playing card about the track such as the title, subtitle, and various icons. To learn how to do this, see Update the media metadata.

Respond to user action

When the user selects the Now Playing card, the system opens the app that owns the session. If your app provides a PendingIntent to setSessionActivity(), the system launches the activity you specify, as shown in the following code snippet. If not, the default system intent opens. The activity you specify must provide playback controls that allow users to pause or stop playback.

Kotlin

val pi: PendingIntent = Intent(context, MyActivity::class.java).let { intent ->
    PendingIntent.getActivity(
            context, 99 /*request code*/,
            intent,
            PendingIntent.FLAG_UPDATE_CURRENT
    )
}
session.setSessionActivity(pi)

Java

Intent intent = new Intent(context, MyActivity.class);
PendingIntent pi = PendingIntent.getActivity(context, 99 /*request code*/,
        intent, PendingIntent.FLAG_UPDATE_CURRENT);
session.setSessionActivity(pi);