attachMediaSession

fun KitePlayer.attachMediaSession(context: Context, notification: MediaNotificationOptions? = null, background: BackgroundPolicy? = BackgroundPolicy.ContinueAudio, interruptions: InterruptionPolicy? = InterruptionPolicy(), skipInterval: Duration = 15.seconds): KitePlayerMediaSession

Creates the media session for this player, with what an app needs for the lock screen and for background playback, and returns it.

  • The lock screen, headset buttons, car and quick settings controls follow the player.

  • notification adds the media notification, which keeps the app in the foreground while it plays. It needs the manifest entries that KitePlayerMediaService lists. Null adds none.

  • background says what happens when the app leaves the screen. Null leaves that alone.

  • interruptions takes audio focus, so a call or another app pauses or ducks the player, and it pauses when the headphones come out. Null turns that off.

The session owns all of it and closes it in the right order. It also closes itself when the player closes, so most apps never close it by hand.

val player = KitePlayer()
player.attachMediaSession(context, MediaNotificationOptions(smallIcon = R.drawable.ic_notification))

Throws

when notification is given and the manifest does not declare KitePlayerMediaService.

fun KitePlayer.attachMediaSession(background: BackgroundPolicy? = BackgroundPolicy.ContinueAudio, interruptions: InterruptionPolicy? = InterruptionPolicy(), pictureInPicture: KitePlayerPictureInPicture? = null, skipInterval: Duration = 15.seconds): KitePlayerMediaSession

Creates the media session for this player, with what an app needs for the lock screen and for background playback, and returns it.

  • The now playing card and its buttons follow the player.

  • background says what happens when the app leaves the screen, and pictureInPicture keeps the picture decoding while its small window shows. Null leaves that alone.

  • interruptions pauses for a call and when the headphones come out. Null turns that off.

The session owns all of it and closes it with the player, so most apps never close it by hand. Call this on the main thread.