just_audio icon indicating copy to clipboard operation
just_audio copied to clipboard

AudioPlayer.setAudioSources is broken on web (since v0.10.1)

Open d0bry opened this issue 7 months ago • 4 comments

Which API doesn't behave as documented, and how does it misbehave? AudioPlayer.setAudioSources on web, when called multiple times for the same player. The first call works properly, the subsequent ones don't change the audio source.

Minimal reproduction project You can use example_playlist.dart and replace the action in floatingActionButton:

floatingActionButton: FloatingActionButton(
  child: const Icon(Icons.add),
  onPressed: () {
    _player.setAudioSources([
      AudioSource.uri(
        Uri.parse("asset:///audio/nature.mp3"),
        tag: AudioMetadata(
          album: "Public Domain",
          title: "Nature Sounds ${++_addedCount}",
          artwork: "https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg",
        ),
      ),
    ]);
  },
),

To Reproduce (i.e. user steps, not code) Start the player and press the floating action button. v0.10.0 - switches to the new source v0.10.1 - keeps playing the old source

Additional context After some digging it looks that the issue was introduced here: https://github.com/ryanheise/just_audio/commit/1b210605341b55064a1ced3c5f91396bf0b8b3f9#diff-0216d3b390b4cdf5c0f4ab8df3f5b73b4ee8fc493637f275724875ef70ba8d7eL863

Since _playlist.clear/_playlist.addAll were replaced with _playlist._init, the player cached in just_audio_web is not removed and gets reused (with the old audio source). https://github.com/ryanheise/just_audio/blob/minor/just_audio_web/lib/just_audio_web.dart#L537

d0bry avatar May 06 '25 09:05 d0bry

Hi. Is there any workaround?

justitman123 avatar Aug 02 '25 13:08 justitman123

Hi. Is there any workaround?

I'm just sticking with v0.10.0.

d0bry avatar Aug 04 '25 07:08 d0bry

I've had to pin to v0.10.0 too.

nfairfield avatar Aug 29 '25 17:08 nfairfield

This is the workaround we are using until this is fixed.

if (TecPlatform.isWeb) {
  await _player!.clearAudioSources();
  await _player!.addAudioSource(source);
} else {
  await _player!.setAudioSource(source);
}

skiluk avatar Sep 24 '25 18:09 skiluk