preCache method
PreCache a video. On Android, the future succeeds when
the requested size, specified in
PipFlutterPlayerCacheConfiguration.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(
PipFlutterPlayerDataSource pipFlutterPlayerDataSource) async {
final cacheConfig = pipFlutterPlayerDataSource.cacheConfiguration ??
const PipFlutterPlayerCacheConfiguration(useCache: true);
final dataSource = DataSource(
sourceType: DataSourceType.network,
uri: pipFlutterPlayerDataSource.url,
useCache: true,
headers: pipFlutterPlayerDataSource.headers,
maxCacheSize: cacheConfig.maxCacheSize,
maxCacheFileSize: cacheConfig.maxCacheFileSize,
cacheKey: cacheConfig.key,
videoExtension: pipFlutterPlayerDataSource.videoExtension,
);
return VideoPlayerController.preCache(dataSource, cacheConfig.preCacheSize);
}