loadAndPlay method

Future<int> loadAndPlay(
  1. ByteData rawSound, {
  2. int priority = _DEFAULT_SOUND_PRIORITY,
  3. int repeat = 0,
  4. double rate = 1.0,
})

Prepares sound for playing and plays immediately when loaded

loadAndPlay(await rootBundle.load("sounds/dices.m4a")); // loads file from assets

Returns soundId for future use in play (soundId > -1) or -1 when sound file failed to load

See also:

  • load, which allows for precaching the sound data

web

priority and repeat are ignored. The sound is played only once.

Implementation

Future<int> loadAndPlay(ByteData rawSound,
    {int priority = _DEFAULT_SOUND_PRIORITY,
    int repeat = 0,
    double rate = 1.0}) async {
  int soundId = await load(rawSound, priority: priority);
  if (soundId > -1) {
    play(soundId, repeat: repeat, rate: rate);
  }
  return soundId;
}