loadAndPlayUri method

Future<int> loadAndPlayUri(
  1. String uri, {
  2. int priority = _DEFAULT_SOUND_PRIORITY,
  3. int repeat = 0,
  4. double rate = 1.0,
})

Prepares sound for playing and plays immediately after loading

Loads sound data from file pointed by uri

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

See also:

  • loadUri, which allows for precaching the sound data

web

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

Implementation

Future<int> loadAndPlayUri(String uri,
    {int priority = _DEFAULT_SOUND_PRIORITY,
    int repeat = 0,
    double rate = 1.0}) async {
  assert(!_disposed, "Soundpool instance was already disposed");
  int soundId = await loadUri(uri, priority: priority);
  if (soundId > -1) {
    play(soundId, repeat: repeat, rate: rate);
  }
  return soundId;
}