PlaybackService

abstract class PlaybackService : Service

Playback service that handles background playback and media notification for a player.

Permissions

Add the following permissions to your AndroidManifest.xml:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>

Service Declaration

Declare your PlaybackService in your AndroidManifest.xml as follows:

<service android:name=".YourService" android:foregroundServiceType="mediaPlayback" />

Limitations

  • Service Termination: the service is stopped when the last ServiceConnection is unbound. This can occur, for example, if the binding is done within an Activity without handling orientation changes. Each rotation could potentially kill the service.

  • External Service Integration: the player is not seamlessly integrated with external services like Android Auto. For Android Auto, you would need to create a MediaLibraryService.

Usage

Subclass this abstract class and implement the pendingIntent method to provide a PendingIntent for the MediaSession's session activity. You can customize the notification by overriding the createNotificationBuilder and onMediaSessionCreated methods.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
inner class ServiceBinder : Binder

A Binder class for interacting with the PlaybackService.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val assets: AssetManager?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val baseContext: Context?
Link copied to clipboard
open val cacheDir: File?
Link copied to clipboard
Link copied to clipboard
open val codeCacheDir: File?
Link copied to clipboard
Link copied to clipboard
open val dataDir: File?
Link copied to clipboard
open val deviceId: Int
Link copied to clipboard
open val display: Display?
Link copied to clipboard
Link copied to clipboard
open val externalCacheDirs: Array<out File?>?
Link copied to clipboard
open val externalMediaDirs: Array<out File?>?
Link copied to clipboard
open val filesDir: File?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val mainLooper: Looper?
Link copied to clipboard
Link copied to clipboard
open val obbDir: File?
Link copied to clipboard
open val obbDirs: Array<out File?>?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val packageName: String?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open val resources: Resources?
Link copied to clipboard
Link copied to clipboard
open val wallpaper: Drawable?

Functions

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun checkCallingUriPermission(p0: Uri?, p1: Int): Int
Link copied to clipboard
Link copied to clipboard
open fun checkContentUriPermissionFull(p0: Uri, p1: Int, p2: Int, p3: Int): Int
Link copied to clipboard
open fun checkPermission(p0: String, p1: Int, p2: Int): Int
Link copied to clipboard
Link copied to clipboard
open fun checkUriPermission(p0: Uri?, p1: Int, p2: Int, p3: Int): Int
open fun checkUriPermission(p0: Uri?, p1: String?, p2: String?, p3: Int, p4: Int, p5: Int): Int
Link copied to clipboard
open fun checkUriPermissions(p0: List<Uri?>, p1: Int, p2: Int, p3: Int): IntArray
Link copied to clipboard
open fun clearWallpaper()
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun createPackageContext(p0: String?, p1: Int): Context?
Link copied to clipboard
open fun createWindowContext(p0: Int, p1: Bundle?): Context
open fun createWindowContext(p0: Display, p1: Int, p2: Bundle?): Context
Link copied to clipboard
open fun databaseList(): Array<out String?>?
Link copied to clipboard
open fun deleteDatabase(p0: String?): Boolean
Link copied to clipboard
open fun deleteFile(p0: String?): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun enforceCallingUriPermission(p0: Uri?, p1: Int, p2: String?)
Link copied to clipboard
open fun enforcePermission(p0: String, p1: Int, p2: Int, p3: String?)
Link copied to clipboard
open fun enforceUriPermission(p0: Uri?, p1: Int, p2: Int, p3: Int, p4: String?)
open fun enforceUriPermission(p0: Uri?, p1: String?, p2: String?, p3: Int, p4: Int, p5: Int, p6: String?)
Link copied to clipboard
open fun fileList(): Array<out String?>?
Link copied to clipboard
fun getColor(p0: Int): Int
Link copied to clipboard
Link copied to clipboard
open fun getDatabasePath(p0: String?): File?
Link copied to clipboard
open fun getDir(p0: String?, p1: Int): File?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun getExternalFilesDirs(p0: String?): Array<out File?>?
Link copied to clipboard
open fun getFileStreamPath(p0: String?): File?
Link copied to clipboard
Link copied to clipboard
fun getString(p0: Int): String
fun getString(p0: Int, vararg p1: Any?): String
Link copied to clipboard
fun <T : Any?> getSystemService(p0: Class<T?>): T?
open fun getSystemService(p0: String): Any?
Link copied to clipboard
open fun getSystemServiceName(p0: Class<*>): String?
Link copied to clipboard
Link copied to clipboard
open fun grantUriPermission(p0: String?, p1: Uri?, p2: Int)
Link copied to clipboard
open fun moveDatabaseFrom(p0: Context?, p1: String?): Boolean
Link copied to clipboard
Link copied to clipboard
open override fun onBind(intent: Intent?): IBinder
Link copied to clipboard
Link copied to clipboard
open override fun onCreate()
Link copied to clipboard
open override fun onDestroy()
Link copied to clipboard
open fun onLowMemory()
Link copied to clipboard

Called when the MediaSession is being created, allowing for customization of the MediaSession.Builder.

Link copied to clipboard
open fun onRebind(p0: Intent?)
Link copied to clipboard
open fun onStart(p0: Intent?, p1: Int)
Link copied to clipboard
open fun onStartCommand(p0: Intent?, p1: Int, p2: Int): Int
Link copied to clipboard
open fun onTaskRemoved(p0: Intent?)
Link copied to clipboard
open fun onTimeout(p0: Int)
open fun onTimeout(p0: Int, p1: Int)
Link copied to clipboard
open fun onTrimMemory(p0: Int)
Link copied to clipboard
open fun onUnbind(p0: Intent?): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun peekWallpaper(): Drawable?
Link copied to clipboard

Returns a PendingIntent that will be used to launch an Activity specified by MediaSession.setSessionActivity when the user interacts with a media notification.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun revokeUriPermission(p0: Uri?, p1: Int)
open fun revokeUriPermission(p0: String?, p1: Uri?, p2: Int)
Link copied to clipboard
open fun sendBroadcast(p0: Intent?)
open fun sendBroadcast(p0: Intent?, p1: String?)
open fun sendBroadcast(p0: Intent, p1: String?, p2: Bundle?)
Link copied to clipboard
open fun sendBroadcastAsUser(p0: Intent?, p1: UserHandle?, p2: String?)
Link copied to clipboard
open fun sendOrderedBroadcast(p0: Intent?, p1: String?)
open fun sendOrderedBroadcast(p0: Intent, p1: String?, p2: Bundle?)
open fun sendOrderedBroadcast(p0: Intent, p1: String?, p2: BroadcastReceiver?, p3: Handler?, p4: Int, p5: String?, p6: Bundle?)
open fun sendOrderedBroadcast(p0: Intent, p1: String?, p2: Bundle?, p3: BroadcastReceiver?, p4: Handler?, p5: Int, p6: String?, p7: Bundle?)
open fun sendOrderedBroadcast(p0: Intent, p1: String?, p2: String?, p3: BroadcastReceiver?, p4: Handler?, p5: Int, p6: String?, p7: Bundle?)
open fun sendOrderedBroadcast(p0: Intent, p1: Int, p2: String?, p3: String?, p4: BroadcastReceiver?, p5: Handler?, p6: String?, p7: Bundle?, p8: Bundle?)
Link copied to clipboard
open fun sendOrderedBroadcastAsUser(p0: Intent?, p1: UserHandle?, p2: String?, p3: BroadcastReceiver?, p4: Handler?, p5: Int, p6: String?, p7: Bundle?)
Link copied to clipboard
open fun sendStickyBroadcast(p0: Intent, p1: Bundle?)
Link copied to clipboard
Link copied to clipboard
open fun sendStickyOrderedBroadcast(p0: Intent?, p1: BroadcastReceiver?, p2: Handler?, p3: Int, p4: String?, p5: Bundle?)
Link copied to clipboard
Link copied to clipboard

Sets the player to be connected to MediaNotification and MediaSession.

Link copied to clipboard
open fun setTheme(p0: Int)
Link copied to clipboard
open fun setWallpaper(p0: Bitmap?)
open fun setWallpaper(p0: InputStream?)
Link copied to clipboard
open fun startActivities(p0: Array<out Intent?>?)
open fun startActivities(p0: Array<out Intent?>?, p1: Bundle?)
Link copied to clipboard
open fun startActivity(p0: Intent?)
open fun startActivity(p0: Intent?, p1: Bundle?)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun startIntentSender(p0: IntentSender?, p1: Intent?, p2: Int, p3: Int, p4: Int)
open fun startIntentSender(p0: IntentSender?, p1: Intent?, p2: Int, p3: Int, p4: Int, p5: Bundle?)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun stopSelf()
fun stopSelf(p0: Int)
Link copied to clipboard
Link copied to clipboard
open fun stopService(p0: Intent?): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard