getControllerForVideo method

  1. @override
Future<VideoPlayerController> getControllerForVideo(
  1. String url,
  2. bool isCaching
)
override

Implementation

@override
Future<VideoPlayerController> getControllerForVideo(
    String url, bool isCaching) async {
  if (isCaching) {
    FileInfo?
        fileInfo; // Variable to store file info if video is found in cache

    try {
      // Attempt to retrieve video file from cache
      fileInfo = await _cacheManager.getFileFromCache(url);
    } catch (e) {
      // Log error if encountered while getting video from cache
      log('Error getting video from cache: $e');
    }

    // Check if video file was found in cache
    if (fileInfo != null) {
      // Log that video was found in cache
      // log('Video found in cache');
      // Return VideoPlayerController for the cached file
      return VideoPlayerController.file(fileInfo.file);
    }

    try {
      // If video is not found in cache, attempt to download it
      // _cacheManager.downloadFile(url);
    } catch (e) {
      // Log error if encountered while downloading video
      log('Error downloading video: $e');
    }
  }

  // Return VideoPlayerController for the video from the network
  return VideoPlayerController.networkUrl(Uri.parse(url));
}