audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

load() and loadall() not working properly

Open millionhz opened this issue 4 years ago • 9 comments

At the start of the app I call the loadall() method but later when i play the sound the following message displays on the terminal: time to call load() for /data/user/0/com.example.xyz/cache/Sound-1.wav: 1 player=xyz.luan.audioplayers.WrappedSoundPool@31aa630

If the sound is already loaded through loadall() method why is this thing being displayed. NOTE: I play the audio by calling its name: _player.play("Sound-1", mode: PlayerMode.LOW_LATENCY);

millionhz avatar Aug 27 '20 18:08 millionhz

I tried something and it seems like it fixed but i want to still report:

  void loadAudioAssets() async {
    for (String audio in [_soundA, _soundB, _correctSound, _wrongSound]) {
      await _player.play(audio, volume: 0, mode: PlayerMode.LOW_LATENCY);
    }
  }

This function is run when the app starts and then when I play these sounds it doesn't say time to call load() for and there is nod delay.

Is this the right way to load sounds?

millionhz avatar Aug 27 '20 19:08 millionhz

@millionhz interesting, can you please also provide a snippet with your "loadAll()" code? just so I can see and reproduce easily

luanpotter avatar Sep 21 '20 03:09 luanpotter

also, what platform are we talking about? (web, android, ios, macos, and is it device or emulator?)

luanpotter avatar Sep 21 '20 03:09 luanpotter

  void loadAudioAssets() {
    _player.loadAll([_soundA, _soundB, _correctSound, _wrongSound]);
  }

I am running the app on an android device running Android 10

millionhz avatar Sep 21 '20 03:09 millionhz

I think it's an issue only with the LOW_LATENCY player, definitely smells like a bug.

luanpotter avatar Oct 13 '20 12:10 luanpotter

I had the same issue. It seems the load and loadAll do only the prefetching from the assets and not the loading in the soundpool. To preload into the soundpool the setUrl(url) can be used. Otherwise they are only loaded at the first call to play().

bobatsar avatar Dec 16 '20 13:12 bobatsar

I have the same issue, has anyone been able to fix this yet?

phamdanh avatar Oct 31 '21 03:10 phamdanh

I have the same issue, has anyone been able to fix this yet?

Try this:

  void loadAudioAssets() async {
    for (String audio in [_soundA, _soundB, _correctSound, _wrongSound]) {
      await _player.play(audio, volume: 0, mode: PlayerMode.LOW_LATENCY);
    }
  }

Playing all the audio files at the very start of the app with volume: 0 will load the assets.

millionhz avatar Oct 31 '21 04:10 millionhz

@millionhz Can you check, is this still a thing with 1.x.x? Thx :)

Edit: Also let's see #1526

Gustl22 avatar Sep 03 '22 10:09 Gustl22