AudioService class Null safety

Provides an API to manage the app's AudioHandler. An app must call init during initialisation to register the AudioHandler that will service all requests to play audio.

Constructors

AudioService()

Properties

hashCode int
The hash code for this object.
read-only, inherited
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
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

addQueueItem Future<void> Function(MediaItem mediaItem)
Deprecated. Use AudioHandler.addQueueItem instead.
@Deprecated("Use AudioHandler.addQueueItem instead."), final
browseMediaChildren List<MediaItem>?
Deprecated. Use AudioHandler.getChildren instead.
@Deprecated("Use AudioHandler.getChildren instead"), read-only
browseMediaChildrenStream Stream<List<MediaItem>>
Deprecated. Directly subscribe to a parent's children via AudioHandler.subscribeToChildren.
@Deprecated("Use AudioHandler.subscribeToChildren instead."), read-only
cacheManager BaseCacheManager
The cache to use when loading artwork. Defaults to DefaultCacheManager.
read-only
click Future<void> Function([MediaButton])
Deprecated. Use AudioHandler.click instead.
@Deprecated("Use AudioHandler.click instead."), final
config AudioServiceConfig
The current configuration.
read-only
currentMediaItem MediaItem?
Deprecated. Use value of AudioHandler.mediaItem instead.
@Deprecated("Use AudioHandler.mediaItem.value instead."), read-only
currentMediaItemStream ValueStream<MediaItem?>
Deprecated. Use AudioHandler.mediaItem instead.
@Deprecated("Use AudioHandler.mediaItem instead."), read-only
customAction Future Function(String, Map<String, dynamic>)
Deprecated. Use AudioHandler.customAction instead.
@Deprecated("Use AudioHandler.customAction instead."), final
customEventStream Stream
Deprecated. Use AudioHandler.customEvent instead.
@Deprecated("Use AudioHandler.customEvent instead."), read-only
fastForward Future<void> Function()
Deprecated. Use AudioHandler.fastForward instead.
@Deprecated("Use AudioHandler.fastForward instead."), final
notificationClicked ValueStream<bool>
A stream that broadcasts the status of the notificationClick event.
read-only
notificationClickEventStream ValueStream<bool>
Deprecated. Use notificationClicked instead.
@Deprecated("Use notificationClicked instead."), read-only
pause Future<void> Function()
Deprecated. Use AudioHandler.pause instead.
@Deprecated("Use AudioHandler.pause instead."), final
play Future<void> Function()
Deprecated. Use AudioHandler.play instead.
@Deprecated("Use AudioHandler.play instead."), final
playbackState PlaybackState
Deprecated. Use value of AudioHandler.playbackState instead.
@Deprecated("Use AudioHandler.playbackState.value instead."), read-only
playbackStateStream ValueStream<PlaybackState>
Deprecated. Use AudioHandler.playbackState instead.
@Deprecated("Use AudioHandler.playbackState instead."), read-only
playFromMediaId Future<void> Function(String, [Map<String, dynamic>])
Deprecated. Use AudioHandler.playFromMediaId instead.
@Deprecated("Use AudioHandler.playFromMediaId instead."), final
playMediaItem Future<void> Function(MediaItem mediaItem)
Deprecated. Use AudioHandler.playMediaItem instead.
@Deprecated("Use AudioHandler.playMediaItem instead."), final
position Stream<Duration>
A stream tracking the current position, suitable for animating a seek bar. To ensure a smooth animation, this stream emits values more frequently on short media items where the seek bar moves more quickly, and less frequenly on long media items where the seek bar moves more slowly. The interval between each update will be no quicker than once every 16ms and no slower than once every 200ms.
late, final
positionStream ValueStream<Duration>
Deprecated. Use position instead.
@Deprecated("Use position instead."), late, final
prepare Future<void> Function()
Deprecated. Use AudioHandler.prepare instead.
@Deprecated("Use AudioHandler.prepare instead."), final
prepareFromMediaId Future<void> Function(String, [Map<String, dynamic>])
Deprecated. Use AudioHandler.prepareFromMediaId instead.
@Deprecated("Use AudioHandler.prepareFromMediaId instead."), final
queue List<MediaItem>?
Deprecated. Use value of AudioHandler.queue instead.
@Deprecated("Use AudioHandler.queue.value instead."), read-only
queueStream ValueStream<List<MediaItem>?>
Deprecated. Use AudioHandler.queue instead.
@Deprecated("Use AudioHandler.queue instead."), read-only
removeQueueItem Future<void> Function(MediaItem mediaItem)
Deprecated. Use AudioHandler.removeQueueItem instead.
@Deprecated("Use AudioHandler.removeQueueItem instead."), final
rewind Future<void> Function()
Deprecated. Use AudioHandler.rewind instead.
@Deprecated("Use AudioHandler.rewind instead."), final
running bool
Deprecated. Use PlaybackState.processingState of AudioHandler.playbackState instead.
@Deprecated("Use PlaybackState.processingState instead."), read-only
runningStream ValueStream<bool>
Deprecated. Use AudioHandler.playbackState instead.
@Deprecated("Use AudioHandler.playbackState instead."), read-only
seekBackward Future<void> Function(bool begin)
Deprecated. Use AudioHandler.seekBackward instead.
@Deprecated("Use audioHandler.seekBackward instead."), final
seekForward Future<void> Function(bool begin)
Deprecated. Use AudioHandler.seekForward instead.
@Deprecated("Use AudioHandler.seekForward instead."), final
seekTo Future<void> Function(Duration position)
Deprecated. Use AudioHandler.seek instead.
@Deprecated("Use AudioHandler.seek instead."), final
setRepeatMode Future<void> Function(AudioServiceRepeatMode repeatMode)
Deprecated. Use AudioHandler.setRepeatMode instead.
@Deprecated("Use AudioHandler.setRepeatMode instead."), final
setShuffleMode Future<void> Function(AudioServiceShuffleMode shuffleMode)
Deprecated. Use AudioHandler.setShuffleMode instead.
@Deprecated("Use AudioHandler.setShuffleMode instead."), final
setSpeed Future<void> Function(double speed)
Deprecated. Use AudioHandler.setSpeed instead.
@Deprecated("Use AudioHandler.setSpeed instead."), final
skipToNext Future<void> Function()
Deprecated. Use AudioHandler.skipToNext instead.
@Deprecated("Use AudioHandler.skipToNext instead."), final
skipToPrevious Future<void> Function()
Deprecated. Use AudioHandler.skipToPrevious instead.
@Deprecated("Use AudioHandler.skipToPrevious instead."), final
stop Future<void> Function()
Deprecated. Use AudioHandler.stop instead.
@Deprecated("Use AudioHandler.stop instead."), final
updateMediaItem Future<void> Function(MediaItem mediaItem)
Deprecated. Use AudioHandler.updateMediaItem instead.
@Deprecated("Use AudioHandler.updateMediaItem instead."), final
updateQueue Future<void> Function(List<MediaItem> queue)
Deprecated. Use AudioHandler.updateQueue instead.
@Deprecated("Use AudioHandler.updateQueue instead."), final

Static Methods

addQueueItemAt(MediaItem mediaItem, int index) Future<void>
Deprecated. Use AudioHandler.insertQueueItem instead.
@Deprecated("Use AudioHandler.insertQueueItem instead.")
addQueueItems(List<MediaItem> mediaItems) Future<void>
Deprecated. Use AudioHandler.addQueueItems instead.
@Deprecated("Use AudioHandler.addQueueItems instead.")
androidForceEnableMediaButtons() Future<void>
In Android, forces media button events to be routed to your active media session.
createPositionStream({int steps = 800, Duration minPeriod = const Duration(milliseconds: 200), Duration maxPeriod = const Duration(milliseconds: 200)}) Stream<Duration>
Creates a new stream periodically tracking the current position. The stream will aim to emit steps position updates at intervals of current MediaItem.duration / steps. This interval will be clipped between minPeriod and maxPeriod. This stream will not emit values while audio playback is paused or stalled.
init<T extends AudioHandler>({required T builder(), AudioServiceConfig? config, BaseCacheManager? cacheManager}) Future<T>
Register the app's AudioHandler with configuration options. This must be called during the app's initialisation so that it is prepared to handle audio requests immediately after a cold restart (e.g. if the user clicks on the play button in the media notification while your app is not running and your app needs to be woken up).
setBrowseMediaParent([String parentMediaId = browsableRootId]) Future<void>
Deprecated. Instead, subscribe directly to a parent's children via AudioHandler.subscribeToChildren.
@Deprecated("Use AudioHandler.subscribeToChildren instead.")
setRating(Rating rating, Map extras) Future<void>
Deprecated. Use AudioHandler.setRating instead.
@Deprecated("Use AudioHandler.setRating instead.")
skipToQueueItem(String mediaId) Future<void>
Deprecated. Use AudioHandler.skipToQueueItem instead.
@Deprecated("Use AudioHandler.skipToQueueItem instead.")
start({required Function backgroundTaskEntrypoint, Map<String, dynamic>? params, String androidNotificationChannelName = "Notifications", String? androidNotificationChannelDescription, int? androidNotificationColor, String androidNotificationIcon = 'mipmap/ic_launcher', bool androidShowNotificationBadge = false, bool androidNotificationClickStartsActivity = true, bool androidNotificationOngoing = false, bool androidResumeOnClick = true, bool androidStopForegroundOnPause = false, bool androidEnableQueue = false, Size? androidArtDownscaleSize, Duration fastForwardInterval = const Duration(seconds: 10), Duration rewindInterval = const Duration(seconds: 10)}) Future<bool>
Deprecated. The new AudioHandler API now automatically starts the service when your implementation enters the playing state. Parameters can be passed via AudioHandler.customAction.
@Deprecated("Use init instead.")

Constants

browsableRootId → const String
The root media ID for browsing media provided by the background task.
'root'
MEDIA_ROOT_ID → const String
Deprecated. Use browsableRootId instead.
@Deprecated("Use browsableRootId instead.")
browsableRootId
recentRootId → const String
The root media ID for browsing the most recently played item(s).
'recent'