I saved a video in my asset folder and i am trying to get the video using the File class.
For example:
Final File video = File(String path);
So my question is where can i find the String path?
I already added this file to the pubspec.yaml
assets:
- assets/mbf.mp4
Thank you
Answer
getVideo() async {
var response = await rootBundle.load('assets/mbf.mp4');
final directory = await getApplicationDocumentsDirectory();
var file = File("${directory.path}/mbf.mp4");
file.writeAsBytesSync(response.buffer.asUint8List());
//Use it with VideoPlayer
controller = VideoPlayerController.file(file)
..addListener(() => setState(() {}))
..setLooping(true)
..initialize().then((_) => controller.play());
}
You need copy file to device and then get path of file.
See exampl code:
void _copyAssetToLocal() async {
try {
var content = await rootBundle.load("assets/intro.mp4");
final directory = await getApplicationDocumentsDirectory();
var file = File("${directory.path}/intro.mp4");
file.writeAsBytesSync(content.buffer.asUint8List());
loadIntroVideoMethod(file.path);
} catch (e) {
}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With