You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[flame_audio] An older Bgm track that finishes loading late replaces the newer one #4260
Follow-up to #4256, where this was left to be fixed separately.
FlameAudio.bgm.play() loads its track into one shared AudioPlayer. If play() is called again before the first track has loaded, both loads run at the same time. When the older one finishes last, its source goes to the player after the newer track has already started, and replaces it. Since #4256 the older call no longer calls resume(), but its setSource() still lands.
What do you expect?
The track from the last play() is the one left playing, however long the earlier ones take to load.
How can we reproduce this?
// menu.mp3 takes longer to load than battle.mp3, for example because it is// larger and not cached yet.unawaited(FlameAudio.bgm.play('music/menu.mp3'));
// A moment later the game switches music.awaitFlameAudio.bgm.play('music/battle.mp3');
With a real Bgm and AudioPlayer, a fake platform underneath and an AudioCache that delays the first file, the platform receives source short.mp3, resume, then source long.mp3.
What steps should take to fix this?
Let one play() at a time load into the player, and keep stop() outside that wait so it still takes effect at once. I have a fix with tests ready and will open a PR.
Affected platforms
All, as the order of calls is decided in Dart. On Android, audioplayers_android prepares and starts a source that is set while the player is playing (read in WrappedPlayer, not tried on a device).
Other information
Flame main at 10f9897 (flame_audio 2.13.0-dev.1, audioplayers 6.8.1), Flutter 3.47.9 stable.
Activity
matthewalberto commentedon Nov 30, 2026
Fix in #4261.