audioplayers
audioplayers copied to clipboard
Always getting wrong duration
AudioPlayer audioPlayer = AudioPlayer();
await audioPlayer.setUrl(path, isLocal: true);
await audioPlayer.getDuration();
Above code always give 5963776 milliseconds for large files near 5-10 mb.
Adding sleep(const Duration(milliseconds: 100));
before calling duration seems to work for me, is it a functionality of a workaround ?
if instead of getDuration()
you use its listener
player.onDurationChanged.listen((Duration d) {
print('Max duration: $d');
setState(() => duration = d);
});
it works fine.
From documentation of onDurationChanged
:
This event returns the duration of the file, when it's available (it might take a while because it's being downloaded or buffered).
Closing in favor of #1033