getVideoUrl function

String getVideoUrl(
  1. EmbeddedVideoSource source,
  2. String baseUrl
)

baseUrl param allows to override the base url of the video.

Implementation

String getVideoUrl(EmbeddedVideoSource source, String baseUrl) {
  String updatedBaseUrl = baseUrl;
  if (kIsWeb && !kReleaseMode) {
    // This allows to test and debug video player scripts in local environment.
    var url = Uri.parse(html.window.location.href);
    updatedBaseUrl = url.origin;
  }

  // Remove trailing slash if any.
  if (updatedBaseUrl.endsWith('/')) {
    updatedBaseUrl = updatedBaseUrl.substring(0, updatedBaseUrl.length - 1);
  }

  switch (source) {
    case EmbeddedVideoSource.youtube:
      return '$updatedBaseUrl/players/youtube.html';
    case EmbeddedVideoSource.vimeo:
      return '$updatedBaseUrl/players/vimeo.html';
  }
}