4

I am trying to get the duration of an audio file and set it to a String. I am using flutter_sound plugin to play the sound. onPlayerStateChanged listen has duration but I don't know how to use it to set a String to duration value without playing the sound.

The main aim is I want to select an audio file which has a Max length of 20 sec. Can anyone please help me solve it?

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
Me BMan
  • 199
  • 4
  • 10

1 Answers1

-3

You can use:

audioplayers: any then await audioPlayer.play(audioFile.path, isLocal: true);
duration = await audioPlayer.getDuration();
Haroun Hajem
  • 5,223
  • 3
  • 26
  • 39
  • 1
    audioplayers: any then await audioPlayer.play(audioFile.path, isLocal: true); then this link return a duration int duration = await audioPlayer.getDuration(); – Sohaib Aslam Feb 02 '20 at 12:54