getOptimalVideoUrls method
Determine which video files is the most likely to play smoothly, based on the supported types and formats available.
Implementation
List<String> getOptimalVideoUrls(String primaryUrl) {
final availableTypes = VideoLoader.supportedTypes.toList();
if (!webm) availableTypes.remove('webm');
if (!mp4) availableTypes.remove('mp4');
if (!ogg) availableTypes.remove('ogg');
final urls = <String>[];
final regex = RegExp(r'([A-Za-z0-9]+)$');
final primaryMatch = regex.firstMatch(primaryUrl);
if (primaryMatch == null) return urls;
if (availableTypes.remove(primaryMatch.group(1))) urls.add(primaryUrl);
if (alternativeUrls != null) {
for (var alternativeUrl in alternativeUrls!) {
final alternativeMatch = regex.firstMatch(alternativeUrl);
if (alternativeMatch == null) continue;
if (availableTypes.contains(alternativeMatch.group(1))) {
urls.add(alternativeUrl);
}
}
} else {
for (var availableType in availableTypes) {
urls.add(primaryUrl.replaceAll(regex, availableType));
}
}
return urls;
}