BackgroundAudioTask class

An audio task that can run in the background and react to audio events.

You should subclass BackgroundAudioTask and override the callbacks for each type of event that your background task wishes to react to. At a minimum, you must override onStart and onStop to handle initialising and shutting down the audio task.

Constructors

BackgroundAudioTask({BaseCacheManager cacheManager})
Subclasses may supply a cacheManager to manage the loading of artwork, or an instance of DefaultCacheManager will be used by default.

Properties

cacheManager BaseCacheManager
final
fastForwardInterval Duration
The fast forward interval passed into AudioService.start.
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
rewindInterval Duration
The rewind interval passed into AudioService.start.
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
onAddQueueItem(MediaItem mediaItem) Future<void>
Called when a client has requested to add a media item to the queue, such as via a call to AudioService.addQueueItem.
onAddQueueItemAt(MediaItem mediaItem, int index) Future<void>
Called when a client has requested to add a media item to the queue at a specified position, such as via a request to AudioService.addQueueItemAt.
onClick(MediaButton button) Future<void>
Called when the media button on the headset is pressed, or in response to a call from AudioService.click. The default behaviour is: [...]
onClose() Future<void>
Called on Android when the user swipes away the notification. The default implementation (which you may override) calls onStop. Note that by default, the service runs in the foreground state which (despite the name) allows the service to run at a high priority in the background without the operating system killing it. While in the foreground state, the notification cannot be swiped away. You can pass a parameter value of true for androidStopForegroundOnPause in the AudioService.start method if you would like the service to exit the foreground state when playback is paused. This will allow the user to swipe the notification away while playback is paused (but it will also allow the operating system to kill your service at any time to free up resources).
onCustomAction(String name, dynamic arguments) Future
Called when a custom action has been sent by the client via AudioService.customAction. The result of this method will be returned to the client.
onFastForward() Future<void>
Called when a client has requested to fast forward, such as via a request to AudioService.fastForward. An implementation of this callback can use the fastForwardInterval property to determine how much audio to skip.
onLoadChildren(String parentMediaId) Future<List<MediaItem>>
Called when a media browser client, such as Android Auto, wants to query the available media items to display to the user.
onPause() Future<void>
Called when a client has requested to pause audio playback, such as via a call to AudioService.pause. You should implement this method to pause audio playback and also broadcast the appropriate state change via AudioServiceBackground.setState.
onPlay() Future<void>
Called when a client has requested to resume audio playback, such as via a call to AudioService.play. You should implement this method to play audio and also broadcast the appropriate state change via AudioServiceBackground.setState.
onPlayFromMediaId(String mediaId) Future<void>
Called when a client has requested to play a media item by its ID, such as via a call to AudioService.playFromMediaId. You should implement this method to play audio and also broadcast the appropriate state change via AudioServiceBackground.setState.
onPlayMediaItem(MediaItem mediaItem) Future<void>
Called when the Flutter UI has requested to play a given media item via a call to AudioService.playMediaItem. You should implement this method to play audio and also broadcast the appropriate state change via AudioServiceBackground.setState. [...]
onPrepare() Future<void>
Called when a client has requested to prepare audio for playback, such as via a call to AudioService.prepare.
onPrepareFromMediaId(String mediaId) Future<void>
Called when a client has requested to prepare a specific media item for audio playback, such as via a call to AudioService.prepareFromMediaId.
onRemoveQueueItem(MediaItem mediaItem) Future<void>
Called when a client has requested to remove a media item from the queue, such as via a request to AudioService.removeQueueItem.
onRewind() Future<void>
Called when a client has requested to rewind, such as via a request to AudioService.rewind. An implementation of this callback can use the rewindInterval property to determine how much audio to skip.
onSeekBackward(bool begin) Future<void>
Called when a client has requested to either begin or end seeking backward.
onSeekForward(bool begin) Future<void>
Called when a client has requested to either begin or end seeking forward.
onSeekTo(Duration position) Future<void>
Called when a client has requested to seek to a position, such as via a call to AudioService.seekTo. If your implementation of seeking causes buffering to occur, consider broadcasting a buffering state via AudioServiceBackground.setState while the seek is in progress.
onSetRating(Rating rating, Map extras) Future<void>
Called when a client has requested to rate the current media item, such as via a call to AudioService.setRating.
onSetRepeatMode(AudioServiceRepeatMode repeatMode) Future<void>
Called when a client has requested to change the current repeat mode.
onSetShuffleMode(AudioServiceShuffleMode shuffleMode) Future<void>
Called when a client has requested to change the current shuffle mode.
onSetSpeed(double speed) Future<void>
Called when the Flutter UI has requested to set the speed of audio playback. An implementation of this callback should change the audio speed and broadcast the speed change to all clients via AudioServiceBackground.setState.
onSkipToNext() Future<void>
Called when a client has requested to skip to the next item in the queue, such as via a request to AudioService.skipToNext. [...]
onSkipToPrevious() Future<void>
Called when a client has requested to skip to the previous item in the queue, such as via a request to AudioService.skipToPrevious. [...]
onSkipToQueueItem(String mediaId) Future<void>
Called when a client has requested to skip to a specific item in the queue, such as via a call to AudioService.skipToQueueItem.
onStart(Map<String, dynamic> params) Future<void>
Called once when this audio task is first started and ready to play audio, in response to AudioService.start. params will contain any params passed into AudioService.start when starting this background audio task.
onStop() Future<void>
Called when a client has requested to terminate this background audio task, in response to AudioService.stop. You should implement this method to stop playing audio and dispose of any resources used. [...]
onTaskRemoved() Future<void>
Called on Android when the user swipes away your app's task in the task manager. Note that if you use the androidStopForegroundOnPause option to AudioService.start, then when your audio is paused, the operating system moves your service to a lower priority level where it can be destroyed at any time to reclaim memory. If the user swipes away your task under these conditions, the operating system will destroy your service, and you may override this method to do any cleanup. For example: [...]
onUpdateMediaItem(MediaItem mediaItem) Future<void>
Called when the Flutter UI has requested to update the details of a media item.
onUpdateQueue(List<MediaItem> queue) Future<void>
Called when the Flutter UI has requested to set a new queue. [...]
toString() String
Returns a string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited