How to Download Video from Online and store it local Device then play video on Flutter apps Using video player?

倖福魔咒の 提交于 2020-12-08 04:40:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!