如何从在线下载视频并将其存储在本地设备上,然后使用视频播放器在 Flutter 应用程序上播放视频? [英] How to Download Video from Online and store it local Device then play video on Flutter apps Using video player?

查看:27
本文介绍了如何从在线下载视频并将其存储在本地设备上,然后使用视频播放器在 Flutter 应用程序上播放视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个 Flutter 应用程序,用户可以通过一个按钮从在线下载所有视频并将其存储在本地设备上,然后使用视频播放器在 Flutter 应用程序上离线播放这些视频?

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?

我通过资产视频做到了这一点.但是,如果我使用资产中的视频并构建应用程序,那么 apk 的大小会更大.这就是为什么我想制作这个颤振应用程序,用户打开应用程序并单击一个按钮,按下通过所选小部件中的链接从预定义服务器下载的列表视频.然后用户可以通过视频播放器播放这些视频.

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.

推荐答案

你可能想试试 dio 打包它是一个http客户端,支持文件下载并本地保存到给定路径.

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.

这是一个代码示例(来源:iampawan 的 Github)

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");
}

这篇关于如何从在线下载视频并将其存储在本地设备上,然后使用视频播放器在 Flutter 应用程序上播放视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆