preCache method

Future<void> preCache(
  1. BetterPlayerDataSource betterPlayerDataSource
)

PreCache a video. On Android, the future succeeds when the requested size, specified in BetterPlayerCacheConfiguration.preCacheSize, is downloaded or when the complete file is downloaded if the file is smaller than the requested size. On iOS, the whole file will be downloaded, since maxCacheFileSize is currently not supported on iOS. On iOS, the video format must be in this list: https://github.com/sendyhalim/Swime/blob/master/Sources/MimeType.swift

Implementation

Future<void> preCache(BetterPlayerDataSource betterPlayerDataSource) async {
  final cacheConfig = betterPlayerDataSource.cacheConfiguration ??
      const BetterPlayerCacheConfiguration(useCache: true);

  final dataSource = DataSource(
    sourceType: DataSourceType.network,
    uri: betterPlayerDataSource.url,
    useCache: true,
    headers: betterPlayerDataSource.headers,
    maxCacheSize: cacheConfig.maxCacheSize,
    maxCacheFileSize: cacheConfig.maxCacheFileSize,
    cacheKey: cacheConfig.key,
    videoExtension: betterPlayerDataSource.videoExtension,
  );

  return VideoPlayerController.preCache(dataSource, cacheConfig.preCacheSize);
}