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
2.01k stars 845 forks source link

Error of Autoplay policy in Chrome not provided to library #1819

Open matecode opened 4 months ago

matecode commented 4 months ago

Checklist

Current bug behaviour

I'm loading an mp3 file in an audioplayer on Flutter Web. As i need the duration of the file anyway to show this to the user, i'm directly setting source, but do not automatically start playing the file. Everything works fine, except the flutter web app is loaded diretly for this "detailed" route, where the audioplayer instance is created. The i got the following error in Browser console:

image wrapped_player.dart:83 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.

I do not start playing the audiofile, i'm just setting source and try getting the duration. I cannot react to this error because it is not forwarded to the log or event-stream with audioplayers.

Expected behaviour

Is there any chance to inform the dart side about this error? I totally understand the issue, but this means that i must load the audiofile after a user click wich then means i cannot get the duration of the file.

Steps to reproduce

No response

Code sample

I'm using riverpod for the audioPlayer instance, nothing fancy here

Code sample ```dart @riverpod Future<(AudioPlayer, Duration)> audioPlayer(AudioPlayerRef ref, Uri uri) async { await audioPlayer.setSource(UrlSource(uri.toString())); final duration = await audioPlayer.getDuration() ?? Duration.zero; ref.onDispose(audioPlayer.dispose); return (audioPlayer, duration); } ```

Affected platforms

web

Platform details

Chrome: Version 126.0.6478.127 (Offical Build) (arm64)

AudioPlayers Version

6.0.0

Build mode

No response

Audio Files/URLs/Sources

No response

Screenshots

No response

Logs

No response

Related issues / more information

No response

Working on PR

yeah