MediaLibraryService2

abstract class MediaLibraryService2 : MediaSessionService2
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ androidx.media.MediaSessionService2
   ↳ androidx.media.MediaLibraryService2

Base class for media library services.

Media library services enable applications to browse media content provided by an application and ask the application to start playing it. They may also be used to control content that is already playing by way of a MediaSession2.

When extending this class, also add the following to your AndroidManifest.xml.

 <service android:name="component_name_of_your_implementation" > <intent-filter> <action android:name="android.media.MediaLibraryService2" /> </intent-filter> </service>

The MediaLibraryService2 class derives from MediaSessionService2. IDs shouldn't be shared between the MediaSessionService2 and MediaSession2. By default, an empty string will be used for ID of the service. If you want to specify an ID, declare metadata in the manifest as follows.

Summary

Nested classes

Contains information that the library service needs to send to the client when MediaBrowser2#getLibraryRoot(Bundle) is called.

Session for the MediaLibraryService2.

Constants
static String

This is the interface name that a service implementing a session service should say that it support -- that is, this is the action it uses for its intent filter.

Inherited constants
Public constructors

Public methods
open Unit

abstract MediaLibraryService2.MediaLibrarySession
onCreateSession(sessionId: String!)

Called when another app requested to start this service.

open IBinder?
onBind(intent: Intent!)

Inherited functions

Constants

SERVICE_INTERFACE

static val SERVICE_INTERFACE: String

This is the interface name that a service implementing a session service should say that it support -- that is, this is the action it uses for its intent filter.

Value: "android.media.MediaLibraryService2"

Public constructors

<init>

MediaLibraryService2()

Public methods

onCreate

open fun onCreate(): Unit

onCreateSession

abstract fun onCreateSession(sessionId: String!): MediaLibraryService2.MediaLibrarySession

Called when another app requested to start this service.

Library service will accept or reject the connection with the MediaLibrarySessionCallback in the created session.

Service wouldn't run if null is returned or session's ID doesn't match with the expected ID that you've specified through the AndroidManifest.xml.

This method will be called on the main thread.

Parameters
sessionId String!: session id written in the AndroidManifest.xml.
Return
MediaLibraryService2.MediaLibrarySession: a new library session
Exceptions
RuntimeException if returned session is invalid

onBind

open fun onBind(intent: Intent!): IBinder?