PlaybackService
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.
Types
A Binder class for interacting with the PlaybackService.
Properties
Functions
Creates a PlayerNotificationManager.Builder for building the notification.
Called when the MediaSession is being created, allowing for customization of the MediaSession.Builder.
Returns a PendingIntent that will be used to launch an Activity specified by MediaSession.setSessionActivity when the user interacts with a media notification.
Sets the player to be connected to MediaNotification and MediaSession.