BaseAudioHandler class Null safety

Base class for implementations of AudioHandler. It provides default implementations of all methods and streams. Each stream in this class is specialized as either a BehaviorSubject or PublishSubject providing an additional add method for emitting values on those streams.

These are BehaviorSubjects provided by this class:

Besides them, there's also customEvent which is a PublishSubject.

You can choose to implement all methods yourself, or you may leverage some mixins to provide default implementations of certain behaviours:

  • QueueHandler provides default implementations of methods for updating and navigating the queue.
  • SeekHandler provides default implementations of methods for seeking forwards and backwards.

Android service lifecycle and state transitions

On Android, the AudioHandler runs inside an Android service. This allows the audio logic to continue running in the background, and also an app that had previously been terminated to wake up and resume playing audio when the user click on the play button in a media notification or headset.

Foreground/background transitions

The underlying Android service enters the foreground state whenever PlaybackState.playing becomes true, and enters the background state whenever PlaybackState.playing becomes false.

Start/stop transitions

The underlying Android service enters the started state whenever PlaybackState.playing becomes true, and enters the stopped state whenever PlaybackState.processingState becomes idle.

Create/destroy lifecycle

The underlying service is created either when a client binds to it, or when it is started, and it is destroyed when no clients are bound to it AND it is stopped. When the Flutter UI is attached to an Android Activity, this will also bind to the service, and it will unbind from the service when the Activity is destroyed. A media notification will also bind to the service.

If the service needs to be created when the app is not already running, your app's main entrypoint will be called in the background which should initialise your AudioHandler.

Inheritance

Constructors

BaseAudioHandler()
Constructor. Normally this is called from subclasses via super.

Properties

androidPlaybackInfo BehaviorSubject<AndroidPlaybackInfo>
A controller for broadcasting the current AndroidPlaybackInfo to the app's UI, media notification and other clients. Example usage:
final
customEvent PublishSubject
A controller for broadcasting a custom event to the app's UI. A shorthand for the event stream is customEvent. Example usage:
final
customState BehaviorSubject
A controller for broadcasting the current custom state to the app's UI. Example usage:
final
hashCode int
The hash code for this object.
read-only, inherited
mediaItem BehaviorSubject<MediaItem?>
A controller for broadcasting the current media item to the app's UI, media notification and other clients. Example usage:
final
playbackState BehaviorSubject<PlaybackState>
A controller for broadcasting the current PlaybackState to the app's UI, media notification and other clients. Example usage:
final
queue BehaviorSubject<List<MediaItem>>
A controller for broadcasting the current queue to the app's UI, media notification and other clients. Example usage:
final
queueTitle BehaviorSubject<String>
A controller for broadcasting the current queue title to the app's UI, media notification and other clients. Example usage:
final
ratingStyle BehaviorSubject<RatingStyle>
A controller for broadcasting the current rating style to the app's UI, media notification and other clients. Example usage:
final
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

addQueueItem(MediaItem mediaItem) Future<void>
Add mediaItem to the queue.
override
addQueueItems(List<MediaItem> mediaItems) Future<void>
Add mediaItems to the queue.
override
androidAdjustRemoteVolume(AndroidVolumeDirection direction) Future<void>
Adjust the remote volume on Android. This works only when using RemoteAndroidPlaybackInfo.
override
androidSetRemoteVolume(int volumeIndex) Future<void>
Set the remote volume on Android. This works only when using RemoteAndroidPlaybackInfo.
override
click([MediaButton button = MediaButton.media]) Future<void>
Process a headset button click, where button defaults to MediaButton.media.
override
customAction(String name, [Map<String, dynamic>? extras]) Future
A mechanism to support app-specific actions.
override
fastForward() Future<void>
Jump forward by AudioServiceConfig.fastForwardInterval.
override
getChildren(String parentMediaId, [Map<String, dynamic>? options]) Future<List<MediaItem>>
Get the children of a parent media item.
override
getMediaItem(String mediaId) Future<MediaItem?>
Get a particular media item.
override
insertQueueItem(int index, MediaItem mediaItem) Future<void>
Insert mediaItem into the queue at position index.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
onNotificationDeleted() Future<void>
Handle the notification being swiped away (Android).
override
onTaskRemoved() Future<void>
Handle the task being swiped away in the task manager (Android).
override
pause() Future<void>
Pause playback.
override
play() Future<void>
Start or resume playback.
override
playFromMediaId(String mediaId, [Map<String, dynamic>? extras]) Future<void>
Play a specific media item.
override
playFromSearch(String query, [Map<String, dynamic>? extras]) Future<void>
Begin playback from a search query.
override
playFromUri(Uri uri, [Map<String, dynamic>? extras]) Future<void>
Play a media item represented by a Uri.
override
playMediaItem(MediaItem mediaItem) Future<void>
Play a specific media item.
override
prepare() Future<void>
Prepare media items for playback.
override
prepareFromMediaId(String mediaId, [Map<String, dynamic>? extras]) Future<void>
Prepare a specific media item for playback.
override
prepareFromSearch(String query, [Map<String, dynamic>? extras]) Future<void>
Prepare playback from a search query.
override
prepareFromUri(Uri uri, [Map<String, dynamic>? extras]) Future<void>
Prepare a media item represented by a Uri for playback.
override
removeQueueItem(MediaItem mediaItem) Future<void>
Remove mediaItem from the queue.
override
removeQueueItemAt(int index) Future<void>
Remove media item from the queue at the specified index.
override
rewind() Future<void>
Jump backward by AudioServiceConfig.rewindInterval. Note: this value must be positive.
override
Search for media items.
override
seek(Duration position) Future<void>
Seek to position.
override
seekBackward(bool begin) Future<void>
Begin or end seeking backward continuously.
override
seekForward(bool begin) Future<void>
Begin or end seeking forward continuously.
override
setCaptioningEnabled(bool enabled) Future<void>
Set whether captioning is enabled.
override
setRating(Rating rating, [Map<String, dynamic>? extras]) Future<void>
Set the rating.
override
setRepeatMode(AudioServiceRepeatMode repeatMode) Future<void>
Set the repeat mode.
override
setShuffleMode(AudioServiceShuffleMode shuffleMode) Future<void>
Set the shuffle mode.
override
setSpeed(double speed) Future<void>
Set the playback speed.
override
skipToNext() Future<void>
Skip to the next item in the queue.
override
skipToPrevious() Future<void>
Skip to the previous item in the queue.
override
skipToQueueItem(int index) Future<void>
Skip to a queue item.
override
stop() Future<void>
Stop playback and release resources.
override
subscribeToChildren(String parentMediaId) ValueStream<Map<String, dynamic>>
Get a value stream that emits service-specific options to send to the client whenever the children under the specified parent change. The emitted options may contain information about what changed. A client that is subscribed to this stream should call getChildren to obtain the changed children.
override
toString() String
A string representation of this object.
inherited
updateMediaItem(MediaItem mediaItem) Future<void>
Update the properties of mediaItem.
override
updateQueue(List<MediaItem> queue) Future<void>
Update to the queue to queue.
override

Operators

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