-
- All Implemented Interfaces:
-
android.content.ComponentCallbacks,android.content.ComponentCallbacks2,kotlinx.coroutines.CoroutineScope
@Deprecated(message = Use the new AudioNavigator from the readium-navigator-media-audio module. This class will be removed in a future 3.x release.) public class MediaService extends MediaBrowserServiceCompat implements CoroutineScope
MediaBrowserServiceCompat implementation holding the current MediaSessionNavigator for background playback.
You should override this service in your app and declare it in your AndroidManifest.xml.
See https://developer.android.com/guide/topics/media-apps/audio-app/building-a-mediabrowserservice
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classMediaService.Companionpublic final classMediaService.ConnectionConnection to any running MediaService instance.
Use a Connection to get a MediaSessionNavigator from a Publication. It will start the service if needed.
-
Field Summary
Fields Modifier and Type Field Description private final MediaBrowserServiceCompat.ConnectionRecordmConnectionFromFwkprivate final ArrayList<MediaBrowserServiceCompat.ConnectionRecord>mPendingConnectionsprivate final ArrayMap<IBinder, MediaBrowserServiceCompat.ConnectionRecord>mConnectionsprivate final MediaBrowserServiceCompat.ConnectionRecordmCurConnectionprivate final MediaBrowserServiceCompat.ServiceHandlermHandlerprivate final MediaSessionCompat.TokenmSessionprivate final CoroutineContextcoroutineContext
-
Constructor Summary
Constructors Constructor Description MediaService()
-
Method Summary
Modifier and Type Method Description CoroutineContextgetCoroutineContext()MediaPlayeronCreatePlayer(MediaSessionCompat mediaSession, PendingMedia media)Creates the instance of MediaPlayer which will be used for playing the given media. UnitonPlayerStopped()Called when the underlying MediaPlayer was stopped. PendingIntent,Publication)>onCreateNotificationIntent(<ERROR CLASS> publicationId, Publication publication)Creates the PendingIntent which will be used to start the media activity when the user activates the media notification. MediaPlayer.NotificationMetadata,Publication,Link)>onCreateNotificationMetadata(<ERROR CLASS> publicationId, Publication publication, Link link)Creates the MediaPlayer.NotificationMetadata for the given resource ,Publication,Link)>link. Bitmap,Publication)>coverOfPublication(<ERROR CLASS> publicationId, Publication publication)Returns the cover for the given ,Publication)>publication which should be used in media notifications. BooleanonCommand(String command, Bundle args, ResultReceiver cb)Handles a custom command delivered by MediaSessionCompat.Callback.onCommand. UnitonResourceLoadFailed(Link link, ReadError error)Called when a resource failed to be loaded, for example because the Internet connection is offline and the resource is streamed. BooleanisClientAuthorized(String packageName, Integer uid)Override to control which app can access the MediaSession through the MediaBrowserService. UnitonCreate()UnitonDestroy()MediaBrowserServiceCompat.BrowserRootonGetRoot(String clientPackageName, Integer clientUid, Bundle rootHints)UnitonLoadChildren(String parentId, MediaBrowserServiceCompat.Result<List<MediaBrowserCompat.MediaItem>> result)-
Methods inherited from class org.readium.r2.navigator.media.MediaService
addSubscription, applyOptions, attachToBaseContext, dump, getBrowserRootHints, getCurrentBrowserInfo, getSessionToken, handleMessageInternal, isValidPackage, notifyChildrenChanged, notifyChildrenChanged, notifyChildrenChanged, onBind, onCustomAction, onLoadChildren, onLoadItem, onSearch, onSubscribe, onUnsubscribe, performCustomAction, performLoadChildren, performLoadItem, performSearch, removeSubscription, setSessionToken -
Methods inherited from class android.app.Service
bindIsolatedService, bindService, bindService, bindService, bindService, bindServiceAsUser, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingOrSelfUriPermissions, checkCallingPermission, checkCallingUriPermission, checkCallingUriPermissions, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermission, checkUriPermissions, clearWallpaper, createAttributionContext, createConfigurationContext, createContext, createContextForSplit, createDeviceContext, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getAttributionSource, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDataDir, getDatabasePath, getDeviceId, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFileStreamPath, getFilesDir, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getParams, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, isUiContext, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerComponentCallbacks, registerDeviceIdChangeListener, registerReceiver, registerReceiver, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeSelfPermissionsOnKill, revokeUriPermission, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startForegroundService, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterComponentCallbacks, unregisterDeviceIdChangeListener, unregisterReceiver, updateServiceGroup -
Methods inherited from class android.content.ContextWrapper
bindIsolatedService, getColor, getColorStateList, getDrawable, getString, getString, getSystemService, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, revokeSelfPermissionOnKill, sendBroadcastWithMultiplePermissions -
Methods inherited from class androidx.media.MediaBrowserServiceCompat
attachBaseContext, getApplication, getForegroundServiceType, onConfigurationChanged, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTimeout, onTrimMemory, onUnbind, startForeground, startForeground, stopForeground, stopForeground, stopSelf, stopSelf, stopSelfResult -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
getCoroutineContext
CoroutineContext getCoroutineContext()
-
onCreatePlayer
MediaPlayer onCreatePlayer(MediaSessionCompat mediaSession, PendingMedia media)
Creates the instance of MediaPlayer which will be used for playing the given media.
The default implementation uses ExoPlayer.
-
onPlayerStopped
Unit onPlayerStopped()
Called when the underlying MediaPlayer was stopped.
-
onCreateNotificationIntent
PendingIntent ,Publication)>onCreateNotificationIntent(<ERROR CLASS> publicationId, Publication publication)
Creates the PendingIntent which will be used to start the media activity when the user activates the media notification.
-
onCreateNotificationMetadata
MediaPlayer.NotificationMetadata ,Publication,Link)>onCreateNotificationMetadata(<ERROR CLASS> publicationId, Publication publication, Link link)
Creates the MediaPlayer.NotificationMetadata for the given resource ,Publication,Link)>link.
The metadata will be used for the media-style notification.
-
coverOfPublication
Bitmap ,Publication)>coverOfPublication(<ERROR CLASS> publicationId, Publication publication)
Returns the cover for the given ,Publication)>publication which should be used in media notifications.
-
onCommand
Boolean onCommand(String command, Bundle args, ResultReceiver cb)
Handles a custom command delivered by MediaSessionCompat.Callback.onCommand.
-
onResourceLoadFailed
Unit onResourceLoadFailed(Link link, ReadError error)
Called when a resource failed to be loaded, for example because the Internet connection is offline and the resource is streamed.
You should present the exception to the user.
-
isClientAuthorized
Boolean isClientAuthorized(String packageName, Integer uid)
Override to control which app can access the MediaSession through the MediaBrowserService. By default, only our own app can.
- Parameters:
packageName- The package name of the application which is requesting access.uid- The UID of the application which is requesting access.
-
onGetRoot
MediaBrowserServiceCompat.BrowserRoot onGetRoot(String clientPackageName, Integer clientUid, Bundle rootHints)
-
onLoadChildren
Unit onLoadChildren(String parentId, MediaBrowserServiceCompat.Result<List<MediaBrowserCompat.MediaItem>> result)
-
-
-
-