MediaLibraryService2
public
abstract
class
MediaLibraryService2
extends MediaSessionService2
java.lang.Object | |||||
↳ | 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.
See also:
Summary
Nested classes | |
---|---|
class |
MediaLibraryService2.LibraryRoot
Contains information that the library service needs to send to the client when
|
class |
MediaLibraryService2.MediaLibrarySession
Session for the |
Constants | |
---|---|
String |
SERVICE_INTERFACE
The |
Inherited constants |
---|
Public constructors | |
---|---|
MediaLibraryService2()
|
Public methods | |
---|---|
IBinder
|
onBind(Intent intent)
Default implementation for |
void
|
onCreate()
Default implementation for |
abstract
MediaLibraryService2.MediaLibrarySession
|
onCreateSession(String sessionId)
Called when another app requested to start this service. |
Inherited methods | |
---|---|
Constants
SERVICE_INTERFACE
public static final String SERVICE_INTERFACE
The Intent
that must be declared as handled by the service.
Constant Value: "android.media.MediaLibraryService2"
Public constructors
MediaLibraryService2
public MediaLibraryService2 ()
Public methods
onBind
public IBinder onBind (Intent intent)
Default implementation for MediaSessionService2
to handle incoming binding
request. If the request is for getting the session, the intent will have action
SERVICE_INTERFACE
.
Override this method if this service also needs to handle binder requests other than
SERVICE_INTERFACE
. Derived classes MUST call through to the super class's
implementation of this method.
Returns | |
---|---|
IBinder |
Binder |
onCreate
public void onCreate ()
Default implementation for MediaSessionService2
to initialize session service.
Override this method if you need your own initialization. Derived classes MUST call through to the super class's implementation of this method.
onCreateSession
public abstract MediaLibraryService2.MediaLibrarySession onCreateSession (String sessionId)
Called when another app requested to start this service.
Library service will accept or reject the connection with the
MediaLibraryService2.MediaLibrarySession.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. |
Returns | |
---|---|
MediaLibraryService2.MediaLibrarySession |
a new library session |
Throws | |
---|---|
RuntimeException |
if returned session is invalid |
Interfaces
Classes
- CallbackDataSource2
- CallbackDataSourceDesc2
- CallbackDataSourceDesc2.Builder
- DataSourceDesc2
- DataSourceDesc2.Builder
- FileDataSourceDesc2
- FileDataSourceDesc2.Builder
- MediaBrowser2
- MediaBrowser2.BrowserCallback
- MediaController2
- MediaController2.ControllerCallback
- MediaController2.PlaybackInfo
- MediaItem2
- MediaItem2.Builder
- MediaLibraryService2
- MediaLibraryService2.LibraryRoot
- MediaLibraryService2.MediaLibrarySession
- MediaLibraryService2.MediaLibrarySession.Builder
- MediaLibraryService2.MediaLibrarySession.MediaLibrarySessionCallback
- MediaMetadata2
- MediaMetadata2.Builder
- MediaPlayer2
- MediaPlayer2.DrmEventCallback
- MediaPlayer2.DrmInfo
- MediaPlayer2.EventCallback
- MediaPlayer2.MetricsConstants
- MediaPlayer2.TrackInfo
- MediaPlayerConnector
- MediaPlayerConnector.PlayerEventCallback
- MediaPlaylistAgent
- MediaPlaylistAgent.PlaylistEventCallback
- MediaSession2
- MediaSession2.Builder
- MediaSession2.CommandButton
- MediaSession2.CommandButton.Builder
- MediaSession2.ControllerInfo
- MediaSession2.SessionCallback
- MediaSessionService2
- MediaSessionService2.MediaNotification
- MediaTimestamp2
- PlaybackParams2
- PlaybackParams2.Builder
- Rating2
- SessionCommand2
- SessionCommandGroup2
- SessionCommandGroup2.Builder
- SessionToken2
- SubtitleData2
- TimedMetaData2
- UriDataSourceDesc2
- UriDataSourceDesc2.Builder
Exceptions