getInitialUrl method
Implementation
Future<void> getInitialUrl(String videoId, {bool isLive = false}) async {
try {
videosList.clear();
if (isLive) {
final videoUrl =
await yt.videos.streams.getHttpLiveStreamUrl(VideoId(videoId));
final response = await get(Uri.parse(videoUrl));
String m3u8Content = response.body;
// Extract stream qualities
List<Map<String, String>> qualities = parseM3U8Content(m3u8Content);
for (var element in qualities) {
videosList.add(
VideoData(
url: element['url'] ?? "",
quality: element['resolution'].toString().split("x").last,
),
);
}
} else {
final videoinfo = await yt.videos.streams.getManifest(videoId);
if (videoinfo.muxed.isNotEmpty) {
final video = VideoData(
url: videoinfo.muxed.first.url.toString(),
quality: videoinfo.muxed.first.qualityLabel,
format: 'mp4',
size: '${videoinfo.muxed.first.size.totalMegaBytes} MB',
);
videosList.add(video);
}
}
} catch (e) {
rethrow;
}
}