

Create and initialize an instance of PlaybackStateCompat and assign it to the session.

Set flags so that the media session can receive callbacks from media controllers and media buttons.You must initialize the session by performing these steps: Initialize the media sessionĪ newly-created media session has no capabilities. On this page the term "media session" means an Note: The best practice for writing a media app is to use Service that owns the media session and its associated player. You should createĪnd initialize a media session in the onCreate() method of the activity or Transparent where the commands originated.Ī media session lives alongside the player that it manages. The media session then delegates theseĬommands to the app that applies them to the media player for which it is Instructing "pause" to Google Assistant). These sources can be physical buttons (such as the playīutton on a headset or TV remote control) or indirect commands (such as Integrating with the media session allowsĪn app to advertise media playback externally and to receive playback commandsįrom external sources. By informing Android that media is playing in an app, playbackĬontrols can be delegated to the app. Media sessions provide a universal way of interacting with an audio or video
