getAvailableCaptionLanguages method
Get the available languages for a video's closed captions with caching.
Implementation
Future<void> getAvailableCaptionLanguages({
required MediaItem item,
required bool Function() checkMounted,
required bool autoGenerated,
}) async {
while (!checkMounted() || _fetchingCaptions.isNotEmpty) {
await Future.delayed(const Duration(milliseconds: 200), () {});
}
String url = item.mediaIdentifier;
try {
_fetchingCaptions.add(url);
ClosedCaptionManifest manifest = await getClosedCaptionsManifest(item);
List<String> autoLanguageCodes = [];
List<String> ccLanguageCodes = [];
for (ClosedCaptionTrackInfo trackInfo in manifest.tracks) {
String languageCode = trackInfo.language.code;
if (trackInfo.isAutoGenerated) {
autoLanguageCodes.add(languageCode);
} else {
ccLanguageCodes.add(languageCode);
}
}
setCaptionsLanguages(
item: item,
captionsLanguages: autoLanguageCodes,
autoGenerated: true,
);
setCaptionsLanguages(
item: item,
captionsLanguages: ccLanguageCodes,
autoGenerated: false,
);
} finally {
_fetchingCaptions.remove(url);
}
}