MediaLibraryService
public abstract class MediaLibraryService extends MediaSessionService
| java.lang.Object | |||||
| ↳ | 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 |
|---|
public final class MediaLibraryService.LibraryParamsParameters for the interaction between |
public final class MediaLibraryService.LibraryParams.BuilderA builder for |
public final class MediaLibraryService.MediaLibrarySession extends MediaSessionAn extended |
public final class MediaLibraryService.MediaLibrarySession.BuilderA builder for |
public interface MediaLibraryService.MediaLibrarySession.Callback extends MediaSession.CallbackAn extended |
Constants |
|
|---|---|
static final String |
SERVICE_INTERFACE = "androidx.media3.session.MediaLibraryService"The action for |
Public constructors |
|---|
Public methods |
|
|---|---|
@Nullable IBinder |
Called when a component is about to bind to the service. |
abstract @Nullable MediaLibraryService.MediaLibrarySession |
onGetSession(MediaSession.ControllerInfo controllerInfo)Called when a is created with this service's . |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
Constants
SERVICE_INTERFACE
public static final String SERVICE_INTERFACE = "androidx.media3.session.MediaLibraryService"
The action for Intent filter that must be declared by the service.
Public constructors
Public methods
onBind
public @Nullable IBinder onBind(@Nullable Intent intent)
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
public abstract @Nullable MediaLibraryService.MediaLibrarySession onGetSession(MediaSession.ControllerInfo controllerInfo)
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.