getDataSource method

Future<String> getDataSource(
  1. MediaItem item
)

Used to get the data source to use as the video URL. This also sets the caching for both manifests.

Implementation

Future<String> getDataSource(MediaItem item) async {
  StreamManifest manifest = getStreamManifest(item);

  List<VideoQuality> qualities = getVideoQualities(manifest);
  VideoQuality currentQuality = preferredQuality;
  while (!qualities.contains(currentQuality)) {
    if (currentQuality.index == 0) {
      currentQuality = qualities.first;
      break;
    }
    VideoQuality fallbackQuality =
        VideoQuality.values[currentQuality.index - 1];
    qualities.remove(currentQuality);
    currentQuality = fallbackQuality;
  }

  return getVideoUrlForQuality(
    manifest: manifest,
    quality: currentQuality,
  );
}