Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get length of audio file without playing it in Flutter/Dart

Tags:

flutter

dart

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?

like image 856
Kyle B. Avatar asked Nov 22 '19 17:11

Kyle B.


People also ask

How do I add mp3 files to flutter?

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.


1 Answers

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.

like image 108
Henok Avatar answered Oct 02 '22 21:10

Henok