audioplayers icon indicating copy to clipboard operation
audioplayers copied to clipboard

Always getting wrong duration

Open abhay-s-rawat opened this issue 3 years ago • 2 comments

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.

abhay-s-rawat avatar Dec 08 '21 03:12 abhay-s-rawat

Adding sleep(const Duration(milliseconds: 100)); before calling duration seems to work for me, is it a functionality of a workaround ?

abhay-s-rawat avatar Dec 08 '21 14:12 abhay-s-rawat

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).

apoleo88 avatar Feb 13 '22 18:02 apoleo88

Closing in favor of #1033

Gustl22 avatar Sep 27 '22 16:09 Gustl22