### Example implementation of skipToQueueItem Source: https://pub.dev/documentation/audio_service/latest/audio_service/QueueHandler/skipToQueueItem.html This example demonstrates how to update the playback state, media item, and trigger playback for the selected index. ```dart playbackState.add(playbackState.value!.copyWith(queueIndex: index)); mediaItem.add(queue.value![index]); player.playAtIndex(index); // use your player's respective API await super.skipToQueueItem(index); ``` -------------------------------- ### Future prepare() Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/prepare.html Prepares media items for playback. This method is intended to be implemented by the audio handler to perform necessary setup tasks before playback begins. ```APIDOC ## Future prepare() ### Description Prepares media items for playback. This method should be implemented to handle the initialization or loading of media content. ### Signature `Future prepare()` ``` -------------------------------- ### play() Source: https://pub.dev/documentation/audio_service/latest/audio_service/CompositeAudioHandler-class.html Starts or resumes audio playback. ```APIDOC ## play() ### Description Initiates playback or resumes playback if it was previously paused. ``` -------------------------------- ### Future play() Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/play.html Starts or resumes audio playback. ```APIDOC ## Future play() ### Description Starts or resumes audio playback. ### Signature `Future play()` ``` -------------------------------- ### Implement play method in BaseAudioHandler Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/play.html Override the play method to define custom playback start or resume logic. ```dart @override Future play() async {} ``` -------------------------------- ### Future seekForward(bool begin) Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/seekForward.html This method is used to signal the start or end of a continuous forward seek operation. ```APIDOC ## seekForward(bool begin) ### Description Begin or end seeking forward continuously. ### Parameters - **begin** (bool) - Required - If true, starts the continuous forward seek; if false, ends it. ``` -------------------------------- ### AudioService.start Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioService/start.html Initializes the audio service with the provided background task entrypoint and configuration parameters. This method is deprecated. ```APIDOC ## Future start({required Function backgroundTaskEntrypoint, Map? params, String androidNotificationChannelName, String? androidNotificationChannelDescription, int? androidNotificationColor, String androidNotificationIcon, bool androidShowNotificationBadge, bool androidNotificationClickStartsActivity, bool androidNotificationOngoing, bool androidResumeOnClick, bool androidStopForegroundOnPause, bool androidEnableQueue, Size? androidArtDownscaleSize, Duration fastForwardInterval, Duration rewindInterval}) ### Description Starts the audio service. This method is deprecated; use the init method instead. ### Parameters - **backgroundTaskEntrypoint** (Function) - Required - The entrypoint function for the background task. - **params** (Map) - Optional - Parameters to pass to the background task. - **androidNotificationChannelName** (String) - Optional - The name of the Android notification channel. - **androidNotificationChannelDescription** (String) - Optional - The description of the Android notification channel. - **androidNotificationColor** (int) - Optional - The color of the Android notification. - **androidNotificationIcon** (String) - Optional - The icon for the Android notification. - **androidShowNotificationBadge** (bool) - Optional - Whether to show the notification badge. - **androidNotificationClickStartsActivity** (bool) - Optional - Whether clicking the notification starts the activity. - **androidNotificationOngoing** (bool) - Optional - Whether the notification is ongoing. - **androidResumeOnClick** (bool) - Optional - Whether to resume on click. - **androidStopForegroundOnPause** (bool) - Optional - Whether to stop foreground service on pause. - **androidEnableQueue** (bool) - Optional - Whether to enable the queue. - **androidArtDownscaleSize** (Size) - Optional - The size to downscale artwork. - **fastForwardInterval** (Duration) - Optional - The interval for fast forward. - **rewindInterval** (Duration) - Optional - The interval for rewind. ### Returns - **Future** - Returns true if the service started successfully. ``` -------------------------------- ### prepareFromSearch(String query, [Map? extras]) Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/prepareFromSearch.html Prepares the audio handler for playback based on a provided search query. ```APIDOC ## prepareFromSearch ### Description Prepares playback from a search query. ### Signature `Future prepareFromSearch(String query, [Map? extras])` ### Parameters - **query** (String) - Required - The search query string to prepare playback for. - **extras** (Map?) - Optional - Additional metadata or parameters for the search request. ``` -------------------------------- ### Implementation of the deprecated onStart method Source: https://pub.dev/documentation/audio_service/latest/audio_service/BackgroundAudioTask/onStart.html This method is deprecated and should be replaced by AudioService.init. Parameters can be passed using AudioHandler.customAction. ```dart @Deprecated("Use AudioService.init instead.") Future onStart(Map? params) async {} ``` -------------------------------- ### inner property Source: https://pub.dev/documentation/audio_service/latest/audio_service/SwitchAudioHandler-class.html Property to get or set the current inner AudioHandler. ```APIDOC ## Property: inner ### Description The current inner AudioHandler that this SwitchAudioHandler will delegate to. This property can be set to switch the underlying handler at any time. ### Type `AudioHandler` ``` -------------------------------- ### Get inner AudioHandler Source: https://pub.dev/documentation/audio_service/latest/audio_service/SwitchAudioHandler/inner.html Retrieves the current AudioHandler instance that the SwitchAudioHandler delegates to. ```dart AudioHandler get inner => _inner; ``` -------------------------------- ### prepareFromUri(Uri uri, [Map? extras]) Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/prepareFromUri.html Prepares a media item represented by a Uri for playback. ```APIDOC ## prepareFromUri ### Description Prepares a media item represented by a Uri for playback. ### Signature `Future prepareFromUri(Uri uri, [Map? extras])` ### Parameters - **uri** (Uri) - Required - The URI of the media item to prepare. - **extras** (Map?) - Optional - Additional metadata or configuration for the preparation process. ``` -------------------------------- ### Deprecated AudioService.start implementation Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioService/start.html This method is deprecated and should be replaced by the init method. It handles background task entry and service configuration. ```dart @Deprecated("Use init instead.") static Future start({ required Function backgroundTaskEntrypoint, Map? 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), }) async { if (!androidEnableQueue) { // ignore: avoid_print print('NOTE: androidEnableQueue is always true from 0.18.0 onwards.'); } if (_cacheManager != null && _handler.playbackState.hasValue) { if (_handler.playbackState.nvalue!.processingState != AudioProcessingState.idle) { return false; } } AudioServiceBackground._startCompleter = Completer(); backgroundTaskEntrypoint(); final task = await AudioServiceBackground._startCompleter!.future; task._handler = _BackgroundAudioHandler(); task._handler._task = task; AudioServiceBackground._startCompleter = null; if (_cacheManager == null) { _compatibilitySwitcher.inner = task._handler; await init( builder: () => _compatibilitySwitcher, config: AudioServiceConfig( androidResumeOnClick: androidResumeOnClick, androidNotificationChannelName: androidNotificationChannelName, androidNotificationChannelDescription: androidNotificationChannelDescription, notificationColor: androidNotificationColor != null ? Color(androidNotificationColor) : null, androidNotificationIcon: androidNotificationIcon, androidShowNotificationBadge: androidShowNotificationBadge, androidNotificationClickStartsActivity: androidNotificationClickStartsActivity, androidNotificationOngoing: androidNotificationOngoing, androidStopForegroundOnPause: androidStopForegroundOnPause, artDownscaleWidth: androidArtDownscaleSize?.width.round(), artDownscaleHeight: androidArtDownscaleSize?.height.round(), fastForwardInterval: fastForwardInterval, rewindInterval: rewindInterval, ), ); } else { _compatibilitySwitcher.inner = task._handler; } await task.onStart(params); return true; } ``` -------------------------------- ### Duration get position Source: https://pub.dev/documentation/audio_service/latest/audio_service/PlaybackState/position.html Retrieves the current playback position as a Duration object. ```APIDOC ## Duration get position ### Description Returns the current playback position. If the audio is playing and in the ready state, it calculates the position based on the last update time and playback speed; otherwise, it returns the last known update position. ### Signature `Duration get position` ### Returns - **Duration** - The current playback position. ``` -------------------------------- ### AudioService.init Source: https://pub.dev/documentation/audio_service/latest/audio_service/audio_service-library.html Initializes the audio service and registers the handler that will service all requests to play audio. ```APIDOC ## AudioService.init ### Description Registers the AudioHandler that will service all requests to play audio. This must be called during application initialization. ### Parameters - **handler** (AudioHandler) - Required - The handler instance to manage audio playback. - **config** (AudioServiceConfig) - Optional - Configuration options for the service. ``` -------------------------------- ### ValueStream get customState Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/customState.html Accesses the stream of custom states provided by the AudioHandler. ```APIDOC ## Property: customState ### Description A stream of custom states that can be observed by the user to track changes in the audio handler's state. ### Signature `ValueStream get customState` ### Return Type - **ValueStream** - A stream that emits the current and subsequent custom states. ``` -------------------------------- ### static Future run(BackgroundAudioTask taskBuilder()) Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioServiceBackground/run.html Initializes a background audio task. This method is deprecated and should be replaced with AudioService.init. ```APIDOC ## static Future run(BackgroundAudioTask taskBuilder()) ### Description Initializes a background audio task. This method is marked as deprecated. ### Signature `static Future run(BackgroundAudioTask Function() taskBuilder)` ### Parameters - **taskBuilder** (BackgroundAudioTask Function()) - Required - A function that returns a BackgroundAudioTask instance. ### Note This method is deprecated. Use `AudioService.init` instead. ``` -------------------------------- ### ValueStream get queueTitle Source: https://pub.dev/documentation/audio_service/latest/audio_service/CompositeAudioHandler/queueTitle.html Retrieves a ValueStream that emits the current title of the audio queue. ```APIDOC ## Property: queueTitle ### Description A ValueStream that provides the current title of the audio queue. This property allows listeners to receive updates whenever the queue title changes. ### Signature `ValueStream get queueTitle` ### Returns - **ValueStream** - A stream containing the current queue title string. ``` -------------------------------- ### seekBackward method implementation Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/seekBackward.html This method is used to signal the start or end of a continuous backward seek operation. ```dart @override Future seekBackward(bool begin) async {} ``` -------------------------------- ### RemoteAndroidPlaybackInfo constructor Source: https://pub.dev/documentation/audio_service/latest/audio_service/RemoteAndroidPlaybackInfo/RemoteAndroidPlaybackInfo.html Initializes a new instance of RemoteAndroidPlaybackInfo with the specified volume control type, maximum volume, and current volume. ```APIDOC ## RemoteAndroidPlaybackInfo constructor ### Description Creates a new instance of RemoteAndroidPlaybackInfo to manage Android playback volume settings. ### Parameters - **volumeControlType** (AndroidVolumeControlType) - Required - The type of volume control to be used. - **maxVolume** (int) - Required - The maximum volume level. - **volume** (int) - Required - The current volume level. ``` -------------------------------- ### Dynamic invocation error example Source: https://pub.dev/documentation/audio_service/latest/audio_service/QueueHandler/noSuchMethod.html Demonstrates a runtime error caused by calling a nonexistent method on a dynamic object. ```dart dynamic object = 1; object.add(42); // Statically allowed, run-time error ``` -------------------------------- ### AudioServiceConfig Constructor Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioServiceConfig-class.html Creates a configuration object used to initialize the AudioService with custom settings. ```APIDOC ## AudioServiceConfig({bool androidResumeOnClick, String? androidNotificationChannelId, String androidNotificationChannelName, String? androidNotificationChannelDescription, Color? notificationColor, String androidNotificationIcon, bool androidShowNotificationBadge, bool androidNotificationClickStartsActivity, bool androidNotificationOngoing, bool androidStopForegroundOnPause, int? artDownscaleWidth, int? artDownscaleHeight, Duration fastForwardInterval, Duration rewindInterval, bool preloadArtwork, Map? androidBrowsableRootExtras}) ### Description Initializes a new configuration object for the AudioService. ### Parameters - **androidResumeOnClick** (bool) - Optional - Whether on Android a media button click wakes up the media session and resumes playback. - **androidNotificationChannelId** (String?) - Optional - The ID of the media notification channel. - **androidNotificationChannelName** (String) - Optional - The name of the media notification channel. - **androidNotificationChannelDescription** (String?) - Optional - A description of the media notification channel. - **notificationColor** (Color?) - Optional - The color to use on the background of the notification on Android. - **androidNotificationIcon** (String) - Optional - The icon resource to be used in the Android media notification. - **androidShowNotificationBadge** (bool) - Optional - Whether notification badges should appear on a launcher icon. - **androidNotificationClickStartsActivity** (bool) - Optional - Whether the application activity will be opened on click on notification. - **androidNotificationOngoing** (bool) - Optional - Whether the notification can be swiped away. - **androidStopForegroundOnPause** (bool) - Optional - Whether the Android service should switch to a lower priority state when playback is paused. - **artDownscaleWidth** (int?) - Optional - Maximum pixel width for artwork downscaling. - **artDownscaleHeight** (int?) - Optional - Maximum pixel height for artwork downscaling. - **fastForwardInterval** (Duration) - Optional - The interval used in AudioHandler.fastForward. - **rewindInterval** (Duration) - Optional - The interval used in AudioHandler.rewind. - **preloadArtwork** (bool) - Optional - Whether to preload artwork. - **androidBrowsableRootExtras** (Map?) - Optional - Extras to report on Android in response to an onGetRoot request. ``` -------------------------------- ### int get hashCode Source: https://pub.dev/documentation/audio_service/latest/audio_service/RemoteAndroidPlaybackInfo/hashCode.html Returns the hash code for the RemoteAndroidPlaybackInfo object, calculated based on volumeControlType, maxVolume, and volume. ```APIDOC ## int get hashCode ### Description The hash code for this object. A hash code is a single integer which represents the state of the object that affects operator == comparisons. ### Implementation ```dart @override int get hashCode => Object.hash(volumeControlType, maxVolume, volume); ``` ``` -------------------------------- ### Register AudioHandler during startup Source: https://pub.dev/documentation/audio_service/latest/index.html Initialize the AudioService with a builder and configuration during the application startup process. ```dart Future main() async { // store this in a singleton _audioHandler = await AudioService.init( builder: () => MyAudioHandler(), config: AudioServiceConfig( androidNotificationChannelId: 'com.mycompany.myapp.channel.audio', androidNotificationChannelName: 'Music playback', ), ); runApp(new MyApp()); } ``` -------------------------------- ### Implement prepareFromUri in BaseAudioHandler Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/prepareFromUri.html Override this method to define custom logic for preparing media from a Uri. ```dart @override Future prepareFromUri(Uri uri, [Map? extras]) async {} ``` -------------------------------- ### int get hashCode Source: https://pub.dev/documentation/audio_service/latest/audio_service/PlaybackState/hashCode.html Returns the hash code for the PlaybackState object, calculated based on its internal state properties to ensure compatibility with hash-based data structures. ```APIDOC ## int get hashCode ### Description Returns a single integer representing the state of the PlaybackState object. This is used to maintain consistency when the object is used in hash-based data structures like Set or Map. ### Signature `int get hashCode` ### Implementation Details The hash code is calculated using `Object.hash` and `Object.hashAll` based on the following properties: - processingState - playing - controls - androidCompactActionIndices - systemActions - updatePosition - bufferedPosition - speed - updateTime - errorCode - errorMessage - repeatMode - shuffleMode - captioningEnabled - queueIndex ``` -------------------------------- ### AudioService.init Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioService/init.html Registers the app's AudioHandler with configuration options. This must be called once during app initialization. ```APIDOC ## init ### Description Registers the app's AudioHandler with configuration options. This must be called once during the app's initialisation so that it is prepared to handle audio requests immediately after a cold restart. ### Signature `Future init({required T builder(), AudioServiceConfig? config, BaseCacheManager? cacheManager})` ### Parameters - **builder** (T Function()) - Required - A function that returns the AudioHandler instance. - **config** (AudioServiceConfig) - Optional - Configuration options for the audio service. - **cacheManager** (BaseCacheManager) - Optional - A cache manager to use when loading artwork. Defaults to DefaultCacheManager. ### Exceptions - **PlatformException**: May be thrown on Android if the AndroidManifest.xml is not configured correctly or if the Activity does not provide the correct FlutterEngine. ``` -------------------------------- ### AndroidPlaybackInfo() Source: https://pub.dev/documentation/audio_service/latest/audio_service/AndroidPlaybackInfo/AndroidPlaybackInfo.html The constructor for creating an instance of AndroidPlaybackInfo. ```APIDOC ## AndroidPlaybackInfo() ### Description Creates a new instance of the AndroidPlaybackInfo class. ### Signature `AndroidPlaybackInfo()` ``` -------------------------------- ### Initialize RemoteAndroidPlaybackInfo Source: https://pub.dev/documentation/audio_service/latest/audio_service/RemoteAndroidPlaybackInfo/RemoteAndroidPlaybackInfo.html Use this constructor to define the volume control parameters for Android playback. ```dart RemoteAndroidPlaybackInfo({ required this.volumeControlType, required this.maxVolume, required this.volume, }); ``` -------------------------------- ### Define the prepare abstract method Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/prepare.html This method signature is used to define the preparation logic for media playback. ```dart Future prepare(); ``` -------------------------------- ### Future prepareFromMediaId(String mediaId, [Map? extras]) Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/prepareFromMediaId.html Prepares a specific media item for playback using its unique media identifier. ```APIDOC ## prepareFromMediaId ### Description Prepares a specific media item for playback. ### Signature `Future prepareFromMediaId(String mediaId, [Map? extras])` ### Parameters - **mediaId** (String) - Required - The unique identifier of the media item to prepare. - **extras** (Map) - Optional - Additional metadata or parameters for the preparation process. ``` -------------------------------- ### RemoteAndroidPlaybackInfo constructor Source: https://pub.dev/documentation/audio_service/latest/audio_service/RemoteAndroidPlaybackInfo-class.html Creates an instance of RemoteAndroidPlaybackInfo with the specified volume control type, maximum volume, and current volume. ```APIDOC ## RemoteAndroidPlaybackInfo({required AndroidVolumeControlType volumeControlType, required int maxVolume, required int volume}) ### Description Constructs a new RemoteAndroidPlaybackInfo object to define remote volume playback parameters. ### Parameters - **volumeControlType** (AndroidVolumeControlType) - Required - The type of volume control supported by the session. - **maxVolume** (int) - Required - The maximum volume supported. - **volume** (int) - Required - The current volume. ``` -------------------------------- ### onPrepareFromMediaId(String mediaId) Source: https://pub.dev/documentation/audio_service/latest/audio_service/BackgroundAudioTask/onPrepareFromMediaId.html Prepares the audio player for playback using a specific media ID. This method is deprecated and users should migrate to AudioHandler.prepareFromMediaId. ```APIDOC ## onPrepareFromMediaId(String mediaId) ### Description Prepares the audio player for playback using a specific media ID. This method is marked as deprecated. ### Signature `Future onPrepareFromMediaId(String mediaId)` ### Parameters - **mediaId** (String) - The identifier of the media to prepare. ### Note This method is deprecated. Use `AudioHandler.prepareFromMediaId` instead. ``` -------------------------------- ### call Source: https://pub.dev/documentation/audio_service/latest/audio_service/PlaybackStateCopyWith-class.html Creates a new PlaybackState instance by copying the current state and applying the provided overrides. ```APIDOC ## call ### Description Creates a new PlaybackState instance by copying the current state and applying the provided overrides. ### Signature `PlaybackState call({AudioProcessingState processingState, bool playing, List controls, List? androidCompactActionIndices, Set systemActions, Duration updatePosition, Duration bufferedPosition, double speed, int? errorCode, String? errorMessage, AudioServiceRepeatMode repeatMode, AudioServiceShuffleMode shuffleMode, bool captioningEnabled, int? queueIndex})` ### Parameters - **processingState** (AudioProcessingState) - Optional - **playing** (bool) - Optional - **controls** (List) - Optional - **androidCompactActionIndices** (List?) - Optional - **systemActions** (Set) - Optional - **updatePosition** (Duration) - Optional - **bufferedPosition** (Duration) - Optional - **speed** (double) - Optional - **errorCode** (int?) - Optional - **errorMessage** (String?) - Optional - **repeatMode** (AudioServiceRepeatMode) - Optional - **shuffleMode** (AudioServiceShuffleMode) - Optional - **captioningEnabled** (bool) - Optional - **queueIndex** (int?) - Optional ### Returns - **PlaybackState** - A new instance of PlaybackState with the updated values. ``` -------------------------------- ### Implement the build method Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioServiceWidget/build.html Standard implementation of the build method for the AudioServiceWidget. ```dart @override Widget build(BuildContext context) { return child; } ``` -------------------------------- ### Implementation of the deprecated run method Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioServiceBackground/run.html This method is marked as deprecated and should be replaced by AudioService.init. ```dart @Deprecated("Use AudioService.init instead") static Future run(BackgroundAudioTask Function() taskBuilder) async { final task = taskBuilder(); _startCompleter!.complete(task); } ``` -------------------------------- ### prepareFromUri method signature Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/prepareFromUri.html The abstract method definition for preparing media from a Uri. ```dart Future prepareFromUri(Uri uri, [Map? extras]); ``` -------------------------------- ### onSeekForward(bool begin) Source: https://pub.dev/documentation/audio_service/latest/audio_service/BackgroundAudioTask/onSeekForward.html This method is deprecated and should no longer be used. Developers are advised to use AudioHandler.seekForward instead. ```APIDOC ## onSeekForward(bool begin) ### Description Deprecated method for handling seek forward events. Use AudioHandler.seekForward instead. ### Signature `Future onSeekForward(bool begin)` ### Parameters - **begin** (bool) - Indicates if the seek operation is beginning. ``` -------------------------------- ### prepareFromSearch method signature Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/prepareFromSearch.html Defines the abstract method signature for preparing playback from a search query. ```dart Future prepareFromSearch(String query, [Map? extras]); ``` -------------------------------- ### AudioServiceConfig constructor Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioServiceConfig/AudioServiceConfig.html Creates a configuration object for the audio service with various parameters for Android notification and playback behavior. ```APIDOC ## AudioServiceConfig constructor ### Description Creates a configuration object to define the behavior of the audio service, including Android notification settings and playback intervals. ### Parameters - **androidResumeOnClick** (bool) - Optional - Whether clicking the notification resumes the app. - **androidNotificationChannelId** (String?) - Optional - The ID for the Android notification channel. - **androidNotificationChannelName** (String) - Optional - The name for the Android notification channel. - **androidNotificationChannelDescription** (String?) - Optional - The description for the Android notification channel. - **notificationColor** (Color?) - Optional - The color of the notification. - **androidNotificationIcon** (String) - Optional - The icon resource for the notification. - **androidShowNotificationBadge** (bool) - Optional - Whether to show a notification badge. - **androidNotificationClickStartsActivity** (bool) - Optional - Whether clicking the notification starts the activity. - **androidNotificationOngoing** (bool) - Optional - Whether the notification is ongoing. - **androidStopForegroundOnPause** (bool) - Optional - Whether to stop foreground service on pause. - **artDownscaleWidth** (int?) - Optional - Width for artwork downscaling. - **artDownscaleHeight** (int?) - Optional - Height for artwork downscaling. - **fastForwardInterval** (Duration) - Optional - Interval for fast forward. - **rewindInterval** (Duration) - Optional - Interval for rewind. - **preloadArtwork** (bool) - Optional - Whether to preload artwork. - **androidBrowsableRootExtras** (Map?) - Optional - Extras for the Android browsable root. ``` -------------------------------- ### Future playFromSearch(String query, [Map? extras]) Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/playFromSearch.html Initiates audio playback based on a provided search query string and optional extra parameters. ```APIDOC ## playFromSearch ### Description Begin playback from a search query. ### Signature `Future playFromSearch(String query, [Map? extras])` ### Parameters - **query** (String) - Required - The search query string to initiate playback. - **extras** (Map) - Optional - Additional metadata or parameters for the search request. ``` -------------------------------- ### RemoteAndroidPlaybackInfo.copyWith Source: https://pub.dev/documentation/audio_service/latest/audio_service/RemoteAndroidPlaybackInfo/copyWith.html Creates a copy of the current RemoteAndroidPlaybackInfo instance with specified fields replaced. ```APIDOC ## RemoteAndroidPlaybackInfo.copyWith ### Signature `AndroidPlaybackInfo copyWith({AndroidVolumeControlType? volumeControlType, int? maxVolume, int? volume})` ### Description Creates a copy of this object with fields replaced. If a parameter is not provided, the original value from the instance is preserved. ### Parameters - **volumeControlType** (AndroidVolumeControlType?) - Optional - The new volume control type. - **maxVolume** (int?) - Optional - The new maximum volume value. - **volume** (int?) - Optional - The new current volume value. ``` -------------------------------- ### MediaControl.custom Constructor Implementation Source: https://pub.dev/documentation/audio_service/latest/audio_service/MediaControl/MediaControl.custom.html Initializes a custom media control by setting the action to MediaAction.custom and creating a CustomMediaAction instance. ```dart MediaControl.custom({ required this.androidIcon, required this.label, required String name, Map? extras, }) : action = MediaAction.custom, customAction = CustomMediaAction(name: name, extras: extras) { assert(action != MediaAction.custom || customAction != null); } ``` -------------------------------- ### Initialize AudioServiceConfig Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioServiceConfig/AudioServiceConfig.html Defines the configuration parameters for the audio service, including validation logic for artwork dimensions and notification settings. ```dart const AudioServiceConfig({ this.androidResumeOnClick = true, this.androidNotificationChannelId, this.androidNotificationChannelName = 'Notifications', this.androidNotificationChannelDescription, this.notificationColor, this.androidNotificationIcon = 'mipmap/ic_launcher', this.androidShowNotificationBadge = false, this.androidNotificationClickStartsActivity = true, this.androidNotificationOngoing = false, this.androidStopForegroundOnPause = true, this.artDownscaleWidth, this.artDownscaleHeight, this.fastForwardInterval = const Duration(seconds: 10), this.rewindInterval = const Duration(seconds: 10), this.preloadArtwork = false, this.androidBrowsableRootExtras, }) : assert((artDownscaleWidth != null) == (artDownscaleHeight != null)), assert( !androidNotificationOngoing || androidStopForegroundOnPause, 'The androidNotificationOngoing will make no effect with androidStopForegroundOnPause set to false', ); ``` -------------------------------- ### Implementation of prepareFromMediaId Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/prepareFromMediaId.html The method signature for preparing media playback using a media ID and optional extras. ```dart Future prepareFromMediaId(String mediaId, [Map? extras]); ``` -------------------------------- ### Implementation of prepareFromSearch Source: https://pub.dev/documentation/audio_service/latest/audio_service/CompositeAudioHandler/prepareFromSearch.html This implementation overrides the base method and delegates the search query and optional extras to the inner handler. ```dart @override @mustCallSuper Future prepareFromSearch(String query, [Map? extras]) => _inner.prepareFromSearch(query, extras); ``` -------------------------------- ### Deprecated onPrepare method implementation Source: https://pub.dev/documentation/audio_service/latest/audio_service/BackgroundAudioTask/onPrepare.html This method is deprecated and should be replaced by AudioHandler.prepare. ```dart @Deprecated("Use AudioHandler.prepare instead.") Future onPrepare() async {} ``` -------------------------------- ### copyWith Source: https://pub.dev/documentation/audio_service/latest/audio_service/RemoteAndroidPlaybackInfo-class.html Creates a copy of the RemoteAndroidPlaybackInfo object with optional fields replaced. ```APIDOC ## copyWith({AndroidVolumeControlType? volumeControlType, int? maxVolume, int? volume}) -> AndroidPlaybackInfo ### Description Creates a copy of this object with fields replaced by the provided values. ### Parameters - **volumeControlType** (AndroidVolumeControlType?) - Optional - New volume control type. - **maxVolume** (int?) - Optional - New maximum volume. - **volume** (int?) - Optional - New current volume. ``` -------------------------------- ### Playback Navigation Methods Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler-class.html Methods for navigating through the media queue or search results. ```APIDOC ## skipToNext() ### Description Skips to the next item in the queue. ## skipToPrevious() ### Description Skips to the previous item in the queue. ## skipToQueueItem(int index) ### Description Skips to a specific item in the queue by index. ## fastForward() ### Description Jumps forward by the configured fast forward interval. ## rewind() ### Description Jumps backward by the configured rewind interval. ``` -------------------------------- ### call Source: https://pub.dev/documentation/audio_service/latest/audio_service/MediaItemCopyWith-class.html Creates a new MediaItem instance by copying the existing one and applying the provided overrides. ```APIDOC ## call ### Description Creates a new MediaItem instance with updated properties based on the provided arguments. ### Signature `MediaItem call({String id, String title, String? album, String? artist, String? genre, Duration? duration, Uri? artUri, bool? playable, String? displayTitle, String? displaySubtitle, String? displayDescription, Rating? rating, bool? isLive, Map? extras})` ### Parameters - **id** (String) - Optional - The unique identifier for the media item. - **title** (String) - Optional - The title of the media item. - **album** (String?) - Optional - The album name. - **artist** (String?) - Optional - The artist name. - **genre** (String?) - Optional - The genre of the media. - **duration** (Duration?) - Optional - The duration of the media. - **artUri** (Uri?) - Optional - The URI for the artwork. - **playable** (bool?) - Optional - Whether the item is playable. - **displayTitle** (String?) - Optional - The title to display. - **displaySubtitle** (String?) - Optional - The subtitle to display. - **displayDescription** (String?) - Optional - The description to display. - **rating** (Rating?) - Optional - The rating of the media item. - **isLive** (bool?) - Optional - Whether the media is a live stream. - **extras** (Map?) - Optional - Additional metadata. ### Returns - **MediaItem** - A new instance of MediaItem with the updated values. ``` -------------------------------- ### MediaControl Constructor Implementation Source: https://pub.dev/documentation/audio_service/latest/audio_service/MediaControl/MediaControl.html Defines the required parameters for creating a custom media control, including the icon, label, and action. ```dart const MediaControl({ required this.androidIcon, required this.label, required this.action, this.customAction, }); ``` -------------------------------- ### Implement prepareFromMediaId Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/prepareFromMediaId.html Override this method to define the logic for preparing a media item identified by its media ID. ```dart @override Future prepareFromMediaId(String mediaId, [Map? extras]) async {} ``` -------------------------------- ### MediaControl constructor Source: https://pub.dev/documentation/audio_service/latest/audio_service/MediaControl/MediaControl.html Creates a custom MediaControl instance with the required icon, label, and action parameters. ```APIDOC ## MediaControl constructor ### Description Creates a custom MediaControl instance for use in the audio service. ### Parameters - **androidIcon** (String) - Required - The icon to display on Android. - **label** (String) - Required - The label for the control. - **action** (MediaAction) - Required - The media action to perform. - **customAction** (CustomMediaAction) - Optional - A custom action associated with the control. ``` -------------------------------- ### AudioServiceBackground() Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioServiceBackground/AudioServiceBackground.html The constructor for the AudioServiceBackground class used to initialize the background audio service instance. ```APIDOC ## AudioServiceBackground() ### Description Initializes a new instance of the AudioServiceBackground class. ### Signature `AudioServiceBackground()` ``` -------------------------------- ### Future playFromUri(Uri uri, [Map? extras]) Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/playFromUri.html Plays a media item represented by a Uri. ```APIDOC ## playFromUri ### Description Plays a media item represented by a Uri. ### Signature `Future playFromUri(Uri uri, [Map? extras])` ### Parameters - **uri** (Uri) - Required - The URI of the media item to play. - **extras** (Map?) - Optional - Additional metadata or parameters for the playback request. ``` -------------------------------- ### CustomMediaAction(name, extras) Source: https://pub.dev/documentation/audio_service/latest/audio_service/CustomMediaAction-class.html Constructor to create a new instance of CustomMediaAction. ```APIDOC ## CustomMediaAction({required String name, Map? extras}) ### Description Creates a new CustomMediaAction instance with a specified name and optional extras map. ### Parameters - **name** (String) - Required - The unique identifier for the custom action. - **extras** (Map?) - Optional - Additional data associated with the action. ``` -------------------------------- ### BackgroundAudioTask() Source: https://pub.dev/documentation/audio_service/latest/audio_service/BackgroundAudioTask/BackgroundAudioTask.html The constructor for the BackgroundAudioTask class. ```APIDOC ## BackgroundAudioTask() ### Description Initializes a new instance of the BackgroundAudioTask class. ### Signature BackgroundAudioTask() ``` -------------------------------- ### AndroidContentStyle() Source: https://pub.dev/documentation/audio_service/latest/audio_service/AndroidContentStyle/AndroidContentStyle.html Constructor for creating an instance of AndroidContentStyle. ```APIDOC ## AndroidContentStyle() ### Description Creates a new instance of the AndroidContentStyle class. ### Signature `AndroidContentStyle()` ``` -------------------------------- ### Override prepareFromSearch method Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/prepareFromSearch.html Implementation of the prepareFromSearch method to handle search-based playback preparation. ```dart @override Future prepareFromSearch(String query, [Map? extras]) async {} ``` -------------------------------- ### Queue Management Methods Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler-class.html Methods for managing the audio playback queue. ```APIDOC ## addQueueItem(MediaItem mediaItem) ### Description Adds a single media item to the queue. ## addQueueItems(List mediaItems) ### Description Adds a list of media items to the queue. ## insertQueueItem(int index, MediaItem mediaItem) ### Description Inserts a media item into the queue at the specified index. ## removeQueueItem(MediaItem mediaItem) ### Description Removes a specific media item from the queue. ## removeQueueItemAt(int index) ### Description Removes the media item at the specified index. ``` -------------------------------- ### Implementation of prepareFromUri Source: https://pub.dev/documentation/audio_service/latest/audio_service/CompositeAudioHandler/prepareFromUri.html This method overrides the base implementation and must call the superclass method. It delegates the preparation task to the internal handler. ```dart @override @mustCallSuper Future prepareFromUri(Uri uri, [Map? extras]) => _inner.prepareFromUri(uri, extras); ``` -------------------------------- ### SwitchAudioHandler constructor Source: https://pub.dev/documentation/audio_service/latest/audio_service/SwitchAudioHandler/SwitchAudioHandler.html Initializes a new instance of SwitchAudioHandler with an optional inner audio handler. ```APIDOC ## SwitchAudioHandler(AudioHandler? inner) ### Description Creates a SwitchAudioHandler with an initial `inner` handler. If no handler is provided, it defaults to a no-op handler. ### Parameters - **inner** (AudioHandler?) - Optional - The initial audio handler to be wrapped by the SwitchAudioHandler. ``` -------------------------------- ### Implementation of onPrepareFromMediaId Source: https://pub.dev/documentation/audio_service/latest/audio_service/BackgroundAudioTask/onPrepareFromMediaId.html This method is deprecated. Use AudioHandler.prepareFromMediaId instead. ```dart @Deprecated("Use AudioHandler.prepareFromMediaId instead.") Future onPrepareFromMediaId(String mediaId) async {} ``` -------------------------------- ### MediaControl Constructor Source: https://pub.dev/documentation/audio_service/latest/audio_service/MediaControl-class.html Creates a custom MediaControl instance for standard media actions. ```APIDOC ## MediaControl({required String androidIcon, required String label, required MediaAction action, CustomMediaAction? customAction}) ### Description Creates a custom MediaControl instance. This control is used to represent a button in the Android notification or lock screen. ### Parameters - **androidIcon** (String) - Required - A reference to an Android icon resource (e.g., "drawable/ic_action_pause"). - **label** (String) - Required - A label for the control. - **action** (MediaAction) - Required - The action to be executed by this control. - **customAction** (CustomMediaAction?) - Optional - The custom action name and optional extras. ``` -------------------------------- ### MediaItem Constructor Source: https://pub.dev/documentation/audio_service/latest/audio_service/MediaItem-class.html Creates a new instance of MediaItem with the specified metadata fields. ```APIDOC ## MediaItem({required String id, required String title, String? album, String? artist, String? genre, Duration? duration, Uri? artUri, Map? artHeaders, bool? playable = true, String? displayTitle, String? displaySubtitle, String? displayDescription, Rating? rating, bool? isLive, Map? extras}) ### Description Creates a MediaItem instance representing an audio item or a folder. ### Parameters - **id** (String) - Required - A unique identifier for the item. - **title** (String) - Required - The title of the media item. - **album** (String?) - Optional - The album name. - **artist** (String?) - Optional - The artist name. - **genre** (String?) - Optional - The genre of the item. - **duration** (Duration?) - Optional - The length of the media. - **artUri** (Uri?) - Optional - The URI for the artwork. - **artHeaders** (Map?) - Optional - HTTP headers for the artUri request. - **playable** (bool?) - Optional - Whether the item is playable (default: true). - **displayTitle** (String?) - Optional - Override title for display. - **displaySubtitle** (String?) - Optional - Override subtitle for display. - **displayDescription** (String?) - Optional - Override description for display. - **rating** (Rating?) - Optional - The rating of the item. - **isLive** (bool?) - Optional - Whether the item is a live stream. - **extras** (Map?) - Optional - Additional metadata. ``` -------------------------------- ### Implementation of playFromSearch Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/playFromSearch.html The default implementation of the playFromSearch method in the BaseAudioHandler class. ```dart @override Future playFromSearch(String query, [Map? extras]) async {} ``` -------------------------------- ### Future fastForward() Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/fastForward.html This method triggers a fast-forward action on the audio service, advancing the playback position by the configured interval. ```APIDOC ## Future fastForward() ### Description Jumps forward in the audio playback by the duration specified in `AudioServiceConfig.fastForwardInterval`. ### Signature `Future fastForward()` ``` -------------------------------- ### PlaybackState.call Source: https://pub.dev/documentation/audio_service/latest/audio_service/PlaybackStateCopyWith/call.html Creates or updates a PlaybackState instance with the specified playback parameters. ```APIDOC ## PlaybackState.call ### Description Creates or updates a PlaybackState instance with the specified playback parameters. ### Signature ```dart PlaybackState call({ AudioProcessingState processingState, bool playing, List controls, List? androidCompactActionIndices, Set systemActions, Duration updatePosition, Duration bufferedPosition, double speed, int? errorCode, String? errorMessage, AudioServiceRepeatMode repeatMode, AudioServiceShuffleMode shuffleMode, bool captioningEnabled, int? queueIndex, }) ``` ### Parameters - **processingState** (AudioProcessingState) - The current processing state of the audio. - **playing** (bool) - Whether the audio is currently playing. - **controls** (List) - The list of media controls available. - **androidCompactActionIndices** (List?) - Indices of actions to show in the compact notification view. - **systemActions** (Set) - The set of system-level media actions. - **updatePosition** (Duration) - The current playback position. - **bufferedPosition** (Duration) - The current buffered position. - **speed** (double) - The playback speed. - **errorCode** (int?) - An optional error code. - **errorMessage** (String?) - An optional error message. - **repeatMode** (AudioServiceRepeatMode) - The current repeat mode. - **shuffleMode** (AudioServiceShuffleMode) - The current shuffle mode. - **captioningEnabled** (bool) - Whether captioning is enabled. - **queueIndex** (int?) - The current index in the queue. ``` -------------------------------- ### Initialize BaseAudioHandler Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/BaseAudioHandler.html Call this constructor from subclasses using super to initialize the audio handler. ```dart BaseAudioHandler() : super._(); ``` -------------------------------- ### Implementation of playFromUri Source: https://pub.dev/documentation/audio_service/latest/audio_service/BaseAudioHandler/playFromUri.html The default implementation of the playFromUri method in the BaseAudioHandler class. ```dart @override Future playFromUri(Uri uri, [Map? extras]) async {} ``` -------------------------------- ### Queue Management Methods Source: https://pub.dev/documentation/audio_service/latest/audio_service/QueueHandler-mixin.html Methods for adding, inserting, and removing items from the media queue. ```APIDOC ## addQueueItem(MediaItem mediaItem) ### Description Adds a single `MediaItem` to the end of the queue. ## addQueueItems(List mediaItems) ### Description Adds a list of `MediaItem` objects to the end of the queue. ## insertQueueItem(int index, MediaItem mediaItem) ### Description Inserts a `MediaItem` into the queue at the specified position index. ## removeQueueItem(MediaItem mediaItem) ### Description Removes a specific `MediaItem` from the queue. ## removeQueueItemAt(int index) ### Description Removes the media item located at the specified index from the queue. ``` -------------------------------- ### Initialize IsolatedAudioHandler Source: https://pub.dev/documentation/audio_service/latest/audio_service/IsolatedAudioHandler/IsolatedAudioHandler.html Constructor for creating an IsolatedAudioHandler. It asserts that the platform is not web and sets up a listener for isolate communication. ```dart IsolatedAudioHandler( super.inner, { this.portName = defaultPortName, bool overridePortName = false, }) : assert(!kIsWeb) { _receivePort.listen((dynamic event) async { final request = event as _IsolateRequest; switch (request.method) { case 'playbackState': _syncStream(playbackState, request.arguments![0] as SendPort); request.sendPort.send(null); break; case 'queue': _syncStream(queue, request.arguments![0] as SendPort); request.sendPort.send(null); break; case 'queueTitle': _syncStream(queueTitle, request.arguments![0] as SendPort); request.sendPort.send(null); break; case 'mediaItem': _syncStream(mediaItem, request.arguments![0] as SendPort); request.sendPort.send(null); break; case 'androidPlaybackInfo': _syncStream(androidPlaybackInfo, request.arguments![0] as SendPort); request.sendPort.send(null); break; case 'ratingStyle': _syncStream(ratingStyle, request.arguments![0] as SendPort); request.sendPort.send(null); break; case 'customEvent': _syncStream(customEvent, request.arguments![0] as SendPort); request.sendPort.send(null); break; case 'customState': _syncStream(customState, request.arguments![0] as SendPort); request.sendPort.send(null); break; case 'prepare': await prepare(); request.sendPort.send(null); break; case 'prepareFromMediaId': await prepareFromMediaId( request.arguments![0] as String, request.arguments![1] as Map?, ); request.sendPort.send(null); break; case 'prepareFromSearch': await prepareFromSearch( request.arguments![0] as String, request.arguments![1] as Map?, ); request.sendPort.send(null); break; case 'prepareFromUri': await prepareFromUri( request.arguments![0] as Uri, request.arguments![1] as Map?, ); request.sendPort.send(null); break; case 'play': await play(); request.sendPort.send(null); break; case 'playFromMediaId': await playFromMediaId( request.arguments![0] as String, request.arguments![1] as Map?, ); request.sendPort.send(null); break; case 'playFromSearch': await playFromSearch( request.arguments![0] as String, request.arguments![1] as Map?, ); request.sendPort.send(null); break; case 'playFromUri': await playFromUri( request.arguments![0] as Uri, request.arguments![1] as Map?, ); request.sendPort.send(null); break; case 'playMediaItem': await playMediaItem(request.arguments![0] as MediaItem); request.sendPort.send(null); break; case 'pause': await pause(); request.sendPort.send(null); break; case 'click': await click(request.arguments![0] as MediaButton); request.sendPort.send(null); break; case 'stop': await stop(); request.sendPort.send(null); break; case 'addQueueItem': await addQueueItem(request.arguments![0] as MediaItem); request.sendPort.send(null); break; case 'addQueueItems': await addQueueItems(request.arguments![0] as List); request.sendPort.send(null); break; case 'insertQueueItem': await insertQueueItem( request.arguments![0] as int, request.arguments![1] as MediaItem, ); request.sendPort.send(null); break; case 'updateQueue': await updateQueue(request.arguments![0] as List); request.sendPort.send(null); break; case 'updateMediaItem': await updateMediaItem(request.arguments![0] as MediaItem); request.sendPort.send(null); break; case 'removeQueueItem': ``` -------------------------------- ### Future click([MediaButton button = MediaButton.media]) Source: https://pub.dev/documentation/audio_service/latest/audio_service/AudioHandler/click.html Processes a headset button click. The button parameter defaults to MediaButton.media. ```APIDOC ## Future click([MediaButton button = MediaButton.media]) ### Description Processes a headset button click event. This method is used to handle input from headset buttons. ### Parameters - **button** (MediaButton) - Optional - The specific headset button clicked. Defaults to MediaButton.media. ```