findResolution static method

String findResolution(
  1. AVPTrackInfo? trackInfo
)

遍历最接近的清晰度

Implementation

static String findResolution(AVPTrackInfo? trackInfo) {
  String nearestResolution = qualityDescriptions["unknown"]!;
  if (trackInfo == null ||
      trackInfo.trackType != FlutterAvpdef.AVPTRACK_TYPE_VIDEO) {
    return nearestResolution;
  }
  final int? width = trackInfo.videoWidth;
  final int? height = trackInfo.videoHeight;
  if ((width ?? -1) <= 0 || (height ?? -1) <= 0) {
    return nearestResolution;
  }
  int minDifference = double.maxFinite.toInt();
  for (final MapEntry<String, List<int>> entry
      in trackInfoResolutions.entries) {
    final int resWidth = entry.value[0];
    final int resHeight = entry.value[1];
    final int difference =
        (resWidth - width!).abs() + (resHeight - height!).abs();
    if (difference < minDifference) {
      minDifference = difference;
      nearestResolution = entry.key;
    }
  }
  return nearestResolution;
}