How can I use the params variable from AudioService.start
290
Simply call AudioService.start method and pass your params:
AudioService.start(
backgroundTaskEntrypoint: _yourTaskEntrypoint,
params: {"key1": "value", "key2": "value"},
);
Or call AudioService.customAction for pass your params at task runtime.
Retrieve data in your task:
@override
Future<void> onStart(Map<String, dynamic> params) async {
print(params["key1"]);
}
@override
Future<dynamic> onCustomAction(String name, dynamic arguments) async {
print("$name:$arguments");
}
See example or docs:
https://pub.dev/packages/audio_service/example
https://pub.dev/documentation/audio_service/latest/audio_service/AudioService/start.html
Author by
Dani Raducu
Updated on December 24, 2022Comments
-
Dani Raducu over 1 year
Audioservice.start function is from the package named audio_service for Flutter, developed by Ryan Heise. What I am trying to do is find out a way to pass information through AudioPlayerTask, which is run by AudioService.start.
-
Dani Raducu over 3 yearsAnd how do I retrieved them or access them?
-
MBN over 3 yearsonStart and onCustomAction implementation in your task
-
MBN over 3 yearsand use AudioServiceBackground.sendCustomEvent to send data from task to app ui, listen to AudioService.customEventStream in ui
-
Dani Raducu over 3 yearsThank you very much ;) God bless you!