MediaLibraryService2

abstract class MediaLibraryService2 : MediaSessionService2
kotlin.Any
   ↳ android.content.Context
   ↳ android.content.ContextWrapper
   ↳ android.app.Service
   ↳ androidx.media2.MediaSessionService2
   ↳ androidx.media2.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

Session for the MediaLibraryService2.

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

Constants
static String

The Intent that must be declared as handled by the service.

Inherited constants
Public constructors

Base class for media library services.

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

The Intent that must be declared as handled by the service.

Value: "android.media.MediaLibraryService2"

Public constructors

<init>

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.

Public methods

onCreate

open fun onCreate(): Unit

onCreateSession

@NonNull 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?