MediaLibraryService
abstract class MediaLibraryService : MediaSessionService
| kotlin.Any | |||||
| ↳ | android.content.Context | ||||
| ↳ | android.content.ContextWrapper | ||||
| ↳ | android.app.Service | ||||
| ↳ | androidx.media3.session.MediaSessionService | ||||
| ↳ | androidx.media3.session.MediaLibraryService |
Superclass to be extended by services hosting media library sessions.
It enables applications to browse media content provided by an application, ask the application to start playback, and control the playback.
To extend this class, declare the intent filter in your AndroidManifest.xml.
<service android:name="NameOfYourService"> <intent-filter> <action android:name="androidx.media3.session.MediaLibraryService"> </intent-filter> </service>
You may also declare android.media.browse.MediaBrowserService for compatibility with android.support.v4.media.MediaBrowserCompat so that this service can handle the case.
| See also | |
|---|---|
MediaSessionService |
Summary
Nested types |
|---|
|
Parameters for the interaction between |
|
A builder for |
|
An extended |
|
A builder for |
|
An extended |
Constants |
|
|---|---|
const String! |
SERVICE_INTERFACE = "androidx.media3.session.MediaLibraryService"The action for |
Public constructors |
|---|
Public functions |
|
|---|---|
IBinder? |
Called when a component is about to bind to the service. |
abstract MediaLibraryService.MediaLibrarySession? |
onGetSession(controllerInfo: MediaSession.ControllerInfo!)Called when a is created with this service's . |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
SERVICE_INTERFACE
const val SERVICE_INTERFACE = "androidx.media3.session.MediaLibraryService": String!
The action for Intent filter that must be declared by the service.
Public constructors
Public functions
onBind
fun onBind(intent: Intent?): IBinder?
Called when a component is about to bind to the service.
The default implementation handles the incoming requests from controllers. In this case, the intent will have the action SERVICE_INTERFACE. Override this method if this service also needs to handle actions other than SERVICE_INTERFACE.
This method will be called on the main thread.
onGetSession
abstract fun onGetSession(controllerInfo: MediaSession.ControllerInfo!): MediaLibraryService.MediaLibrarySession?
Called when a is created with this service's . Return a that the controller will connect to, or null} to reject the connection request.
Note: This method must not be called directly by app code.
The service automatically maintains the returned sessions. In other words, a session returned by this method will be added to the service, and removed from the service when the session is closed. You don't need to manually call #addSession(MediaSession) nor * #removeSession(MediaSession).
There are two special cases where the ControllerInfo#getPackageName() returns a non-existent package name:
- When the service is started by a media button event, the package name will be * Intent#ACTION_MEDIA_BUTTON. If you want to allow the service to be started by media button events, do not return null}.
- When a legacy or a *android.support.v4.media.MediaBrowserCompat tries to connect, the package name will be android.service.media.MediaBrowserService#SERVICE_INTERFACE. If you want to allow the service to be bound by the legacy media browsers, do not return null}.
For those special cases, the values returned by ControllerInfo#getUid() and * ControllerInfo#getConnectionHints() have no meaning.
This method will be called on the main thread.
It must return a MediaLibrarySession which is a subclass of MediaSession.