Code Monkey home page Code Monkey logo

m3u8_downloader's Introduction

m3u8_downloader

Flutter m3u8下载器。后台任务下载,支持加密下载。

只实现了Android端,并且只支持单m3u8视频下载(m3u8文件包含了多个ts文件,本质是多个ts同时下载)。

安装

pubspec.yaml

dependencies:
  m3u8_downloader:
    git:
      url: https://github.com/lytian/m3u8_downloader.git

Android权限配置

  <!--网络权限-->
  <uses-permission android:name="android.permission.INTERNET" />

  <!--存储-->
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

使用

  1. 页面初始化时,初始化下载器
WidgetsFlutterBinding.ensureInitialized();
M3u8Downloader.initialize();


/// initialize方法参数说明:
/// - [saveDir] 文件保存位置
/// - [showNotification] 是否显示通知
/// - [connTimeout] 网络连接超时时间
/// - [readTimeout] 文件读取超时时间
/// - [threadCount] 同时下载的线程数
/// - [debugMode] 调试模式
/// - [onSelect] 点击通知的回调
  1. 必须初始化完成后才能使用M3u8Downloader的其他方法
// 下载方法
M3u8Downloader.download(url, name, callback);

// 暂停下载
M3u8Downloader.pause(url);

// 取消下载
M3u8Downloader.cancel(url, true);

// 获取下载状态
M3u8Downloader.isRunning();

// 通过url获取保存的路径
M3u8Downloader.getM3U8Path();

/// download参数说明:
/// - [url] 下载链接地址
/// - [name] 下载文件名。(通知标题)
/// - [progressCallback] 下载进度回调
/// - [successCallback] 下载成功回调
/// - [errorCallback] 下载失败回调
  1. 下载器本身是后台进程下载,看情况暂停和取消下载

  2. download函数中的回调函数,必须是顶层的静态函数

  3. 不支持m3u8多任务下载。因为每一个m3u8都包含了多个ts片段,本身是多任务下载ts片段

示例代码

具体代码请看Example/lib/main.dart

m3u8_downloader's People

Contributors

lytian avatar zhangwei12138 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.