I might be writing this a bit late but just in case anybody looking for a solution soon.
By the moment the official video_player plugin doesn't support video caching over network yet.
But fortunately, there been some attempts by contributors to add caching feature to the video_player plugin
You can track updates and find another PRs here: https://github.com/flutter/flutter/issues/28094
Replace video_player in your pubspec.yaml with
video_player:
git:
url: https://github.com/sanekyy/plugins.git
ref: caching
path: packages/video_player/video_player
In case of you are using chewie or other libraries that depend on video_player plugin add:
dependency_overrides:
video_player:
git:
url: https://github.com/sanekyy/plugins.git
ref: caching
path: packages/video_player/video_player
And now to cache the video pass useCache : true
to
_videoPlayerController = VideoPlayerController.network(videoURL, useCache: true);
By default both maxFileSize and maxCacheSize is set to 10 * 1024 * 1024 bytes.
To adjust the cache size:
VideoPlayerController.setCacheSize(100 * 1024 * 1024, 200 * 1024 * 1024);
Another Solution:
Is to stream the video normally using the official plugin and to cache the video file using flutter_cache_manager simultaneously.
But this will lead to fetch the video twice the first time (Once for streaming through the video_player, Another for downloading the video through the cachemanager)
Here how the scenario would goes:
1- Check with flutter_cache_manager if the video_url is already downloaded and cached.
2- if the video is cached, pass the file path to video_player VideoPlayerController.file(path)
, if not download the file using cachemanager and stream the video using VideoPlayerController.network(videoURL)
(at this moment video is being fetched twice... by videoplayer and cachemanager).