Skip to content

Commit 663fff2

Browse files
gnarhardspydon
andauthored
fix: Initialize audioplayer instances sequentially (#1941)
# Description <!-- Provide a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change. If this is a breaking change, specify explicitly which APIs have been changed. --> When creating lots of audio pools, an "Unknown Error" can happen if too many players are loaded concurrently. By breaking the instantiation of new players into a serially-loaded structure, we can load 100s of players and effectively remove this edge case. ## Checklist <!-- Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (`[x]`). This will ensure a smooth and quick review process. --> - [x] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `refactor:`, `docs:`, `chore:`, `test:`, `ci:` etc). - [x] I have read the [Contributor Guide] and followed the process outlined for submitting PRs. - [x] I have updated/added tests for ALL new/updated/fixed functionality. - [x] I have updated/added relevant documentation and added dartdoc comments with `///`, where necessary. - [x] I have updated/added relevant examples in [example]. ## Breaking Change <!-- Does your PR require audioplayers users to manually update their apps to accommodate your change? If the PR is a breaking change this should be indicated with suffix "!" (for example, `feat!:`, `fix!:`). See [Conventional Commit] for details. --> - [ ] Yes, this is a breaking change. - [x] No, this is *not* a breaking change. <!-- If the PR is breaking, uncomment the following section and add instructions for how to migrate from the currently released version to the new proposed way. --> <!-- ### Migration instructions Before: ``` ``` After: ``` ``` --> ## Related Issues <!-- Provide a list of issues related to this PR from the [issue database]. Indicate which of these issues are resolved or fixed by this PR, i.e. Fixes #xxx !--> <!-- Links --> [issue database]: https://github.com/bluefireteam/audioplayers/issues [Contributor Guide]: https://github.com/bluefireteam/audioplayers/blob/main/contributing.md#feature-requests--prs [Conventional Commit]: https://conventionalcommits.org [example]: https://github.com/bluefireteam/audioplayers/tree/main/packages/audioplayers/example --------- Co-authored-by: Lukas Klingsbo <[email protected]>
1 parent fd6d673 commit 663fff2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/audioplayers/lib/src/audio_pool.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ class AudioPool {
6767
audioContext: audioContext,
6868
);
6969

70-
final players = await Future.wait(
71-
List.generate(minPlayers, (_) => instance._createNewAudioPlayer()),
72-
);
70+
final players = <AudioPlayer>[];
71+
72+
for (var i = 0; i < minPlayers; i++) {
73+
players.add(await instance._createNewAudioPlayer());
74+
}
7375

7476
return instance..availablePlayers.addAll(players);
7577
}

0 commit comments

Comments
 (0)