buildYoutubeEmbedUrl function

String buildYoutubeEmbedUrl({
  1. required EmbeddedYoutubeVideoProperties properties,
  2. required double? width,
  3. required double? height,
  4. required String baseUrl,
})

Implementation

String buildYoutubeEmbedUrl({
  required EmbeddedYoutubeVideoProperties properties,
  required double? width,
  required double? height,
  required String baseUrl,
}) {
  final Map<String, String> queryParams = {
    'video_id': properties.videoId ?? '<video_id>',
    'mute': '${properties.mute}',
    'autoplay': '${properties.autoPlay}',
    'loop': '${properties.loop}',
    if (properties.startAt != null) 'start': '${properties.startAt}',
    if (properties.startAt != null) 'end': '${properties.endAt}',
    'show_fullscreen_button': '${properties.showFullscreenButton}',
    if (width != null) 'width': '${width.toInt()}',
    if (height != null) 'height': '${height.toInt()}',
    'controls': '${properties.showControls}',
    'show_video_annotations': '${properties.showVideoAnnotations}',
    'show_captions': '${properties.showCaptions}',
    'caption_lang': properties.captionLanguage,
  };

  final baseUri = Uri.parse(getVideoUrl(properties.source, baseUrl));
  final String url = Uri(
    scheme: baseUri.scheme,
    host: baseUri.host,
    port: baseUri.port,
    path: baseUri.path,
    queryParameters: queryParams,
  ).toString();
  return url;
}