问题
I want to develop a flutter application where users can download all Videos from Online by one single button and store it local Device then play those videos offline on Flutter apps Using video player?
I did this by assets video. But if I use video from assets and build the application then the apk size will bigger. That's why I want to make this flutter application where users open the app and click one single button by button on pressed the list videos downloaded from the predefined server via a link in selected widgets. Then users can play those videos via video player.
回答1:
You might wanna give a try to the dio package it is an http client that supports file downloading and save it locally to a given path.
Here's a code sample (source: iampawan's Github)
Future downloadFile(String url) async {
Dio dio = Dio();
try {
var dir = await getApplicationDocumentsDirectory();
await dio.download(url, "${dir.path}/myFile.txt", onProgress: (rec, total) {
print("Rec: $rec , Total: $total");
});
} catch (e) {
print(e);
}
print("Download completed");
}
来源:https://stackoverflow.com/questions/59948686/how-to-download-video-from-online-and-store-it-local-device-then-play-video-on-f