duration method

Future<Duration?> duration(
  1. String uri
)

Get the duration of a sound file.

This verb is used to get an estimation of the duration of a sound file. Be aware that it is just an estimation, based on the Codec used and the sample rate.

Implementation

Future<Duration?> duration(String uri) async {
  if (!await (flutterSoundHelper.isFFmpegAvailable())) return null;
  var info = await ffMpegGetMediaInformation(uri);
  if (info == null) {
    return null;
  }
  var format = info['format'];
  if (format == null) return null;
  var duration = format['duration'];
  if (duration == null) return null;
  var d = (double.parse(duration) * 1000.0).round();
  return (duration == null) ? null : Duration(milliseconds: d);
}