bluefireteam / audioplayers

A Flutter package to play multiple audio files simultaneously (Android/iOS/web/Linux/Windows/macOS)
https://pub.dartlang.org/packages/audioplayers
MIT License
1.97k stars 841 forks source link

load() and loadall() not working properly #616

Open millionhz opened 4 years ago

millionhz commented 4 years ago

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 commented 4 years ago

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?

luanpotter commented 3 years ago

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

luanpotter commented 3 years ago

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

millionhz commented 3 years ago
  void loadAudioAssets() {
    _player.loadAll([_soundA, _soundB, _correctSound, _wrongSound]);
  }

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

luanpotter commented 3 years ago

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

bobatsar commented 3 years ago

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().

phamdanh commented 2 years ago

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

millionhz commented 2 years ago

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.

Gustl22 commented 2 years ago

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

Edit: Also let's see #1526