getFormat static method

Future<MediaFormat> getFormat(
  1. File file, {
  2. bool trustExtension = false,
})

Implementation

static Future<MediaFormat> getFormat(File file,
    {bool trustExtension = false}) async {
  MediaFormat? format = kAllFormats
      .select((i) => i.extensions.any((x) => file.path.endsWith(x)));

  int length = await file.length();
  if (format == null || !trustExtension) {
    RandomAccessFile raf = await file.open();
    List<int> headerBytes =
        await raf.read(min(defaultMagicNumbersMaxLength, length));
    raf.close();
    String? mimeType = lookupMimeType(file.path, headerBytes: headerBytes);

    if (mimeType != null) {
      format = kAllFormats.select((i) => i.mimeType == mimeType);
    }
  }

  return format ?? MediaFormat.unknown();
}