I have a problem with my Flutter app. I want to display the videos in the same way as the Reels section of TikTok. Here is a screenshot of my app.
Problem:
It contains video reels, but each video takes time to load.
What I've tried:
I'm also compressing the videos when they're uploaded to the server. Loading still takes time.
Code that I'm using:
void _initializeController() async {
String videoUrl = ConstRes.itemBaseUrl + widget.url!;
_controller = VideoPlayerController.network(videoUrl);
final fileInfo = await getCachedVideo(videoUrl);
if (fileInfo == null) {
await _controller!.initialize();
setState(() {
_controller!.setLooping(true);
_controller!.play();
widget.isLoading.call(false);
widget.function.call(_controller);
});
cacheVideo(videoUrl);
} else {
_controller = VideoPlayerController.file(fileInfo.file);
await _controller!.initialize();
setState(() {
_controller!.setLooping(true);
_controller!.play();
widget.isLoading.call(false);
widget.function.call(_controller);
});
}
}