flutter_video_caching 0.1.6
flutter_video_caching: ^0.1.6 copied to clipboard
Video caching, can use with video_player package. It supports formats like m3u8 and mp4, play and cache videos simultaneously, precache the video before playing.
flutter_video_caching is a powerful flutter plugin for caching video. It can be use with video_player package. It supports formats like m3u8 and mp4, play and cache videos simultaneously, precache the video before playing.
Features #
Multi-format support
: supports common video formats such as m3u8 (HLS) and MP4Memory and file cache
: implements LRU (least recently used) memory cache strategy, combined with local file cache to reduce network requestsPre-caching mechanism
: supports downloading video clips in advance to improve the continuous playback experienceBackground download
: uses Isolate to achieve multi-task parallel download without blocking UI threadsPriority scheduling
: supports setting priorities for download tasks and optimizes resource allocation
Getting started #
dependencies:
flutter_video_caching: 0.1.3
Usage #
1. Init video proxy #
import 'package:flutter_video_caching/flutter_video_caching.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
VideoProxy.init();
runApp(const HomeApp());
}
2. Use with video_player #
playControl = VideoPlayerController.networkUrl(url.toLocalUri());
3. Precache video #
VideoCaching.precache(url);
4. Use in PageView #
PageView.builder(
controller: pageController,
itemCount: urls.length,
itemBuilder: (context, index) {
return VideoPlayerWidget(url: urls[index]);
},
onPageChanged: (index) {
if (index + 1 < urls.length) {
VideoCaching.precache(urls[index + 1], downloadNow: false);
}
},
);
5. Revert video uri proxy when proxy server is broken #
Future initPlayControl(Uri uri) async {
playControl = VideoPlayerController.networkUrl(uri.toLocalUri())..setLooping(true);
playControl.addListener(playListener);
}
void playListener() {
if (playControl.value.hasError) {
print("errorDescription: ${playControl.value.errorDescription}");
if (playControl.value.errorDescription!.contains("Source error")) {
initPlayControl(uri);
}
}
}