I'm trying to display the length of audio files in my Flutter application. I've used both the flutter_sound and audioplayers plugins but I'm not sure how to get the length of the audio file without playing it and getting the duration (which I want to display the length of each audio file in a list so users know how long it is before playing). I haven't been able to find anywhere online that shows how to get the audio file length in dart except from using the duration of the playing audio file in one of those plugins. Anyone know how to get audio file length's in dart?
If you don't have subdirectory, just write : audioCache. load("assets/stuffandmore/ring. mp3"); And please be sure you have correctly added your mp3 file in the assets folder.
This is a late answer but incase if you are still wondering how to do that, There is a audio library just_audio
final player = AudioPlayer();
var duration = await player.setUrl('file.mp3');
Works on both android and IOS, supports both local files and download urls.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With