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

Share:
290
Dani Raducu
Author by

Dani Raducu

Updated on December 24, 2022

Comments

  • Dani Raducu
    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
    Dani Raducu over 3 years
    And how do I retrieved them or access them?
  • MBN
    MBN over 3 years
    onStart and onCustomAction implementation in your task
  • MBN
    MBN over 3 years
    and use AudioServiceBackground.sendCustomEvent to send data from task to app ui, listen to AudioService.customEventStream in ui
  • Dani Raducu
    Dani Raducu over 3 years
    Thank you very much ;) God bless you!