Skip to content

下载模块

点我查看API

集成和使用ESDownloadModule模块。

  • ESDownloadManager是对ESDownloadModule进一步封装。
  • 开发者可以直接使用ESDownloadModule。建议直接使用ESDownloadManager

集成

package.json引入库

点击查看源码
js
"@extscreen/es-downloader": "x.x.x"

初始化下载模块

示例代码

点击查看源码
js
ESDownloadManager.initDefault();

初始化下载数据

示例代码

点击查看源码
js
let download = {
    id: "1",//自定义下载id
    fileUrl: 'http://qcloudcdn-moss.cp47.ott.cibntv.net/project/tvq/qsj_video/2021/12/07/3800609_9c0bae6b6d5df502ffa28f9396a2316e.mp4',
    fileMD5: '6f6bc0aa03aeec7ae8cdf23edc511fcf',
    fileName: 'aaaa.mp4'
}
ESDownloadManager.download(this.download);

开始下载

示例代码

点击查看源码
js
let download = {
    id: "1",//自定义下载id
    fileUrl: 'http://qcloudcdn-moss.cp47.ott.cibntv.net/project/tvq/qsj_video/2021/12/07/3800609_9c0bae6b6d5df502ffa28f9396a2316e.mp4',
    fileMD5: '6f6bc0aa03aeec7ae8cdf23edc511fcf',
    fileName: 'aaaa.mp4'
}
ESDownloadManager.start(this.download);

停止下载

示例代码

点击查看源码
js
let download = {
    id: "1",//自定义下载id
    fileUrl: 'http://qcloudcdn-moss.cp47.ott.cibntv.net/project/tvq/qsj_video/2021/12/07/3800609_9c0bae6b6d5df502ffa28f9396a2316e.mp4',
    fileMD5: '6f6bc0aa03aeec7ae8cdf23edc511fcf',
    fileName: 'aaaa.mp4'
}
ESDownloadManager.stop(this.download);

取消下载

示例代码

点击查看源码
js
let download = {
    id: "1",//自定义下载id
    fileUrl: 'http://qcloudcdn-moss.cp47.ott.cibntv.net/project/tvq/qsj_video/2021/12/07/3800609_9c0bae6b6d5df502ffa28f9396a2316e.mp4',
    fileMD5: '6f6bc0aa03aeec7ae8cdf23edc511fcf',
    fileName: 'aaaa.mp4'
}
ESDownloadManager.cancel(this.download);

监听下载状态

示例代码

点击查看源码
js
export default {
    mixins: [ESDownload],
    methods: {
        onDownloadInit(download) {
        },
        onDownloadStart(download) {
        },
        onDownloadStop(download) {
        },
        onDownloadCancel(download) {
        },
        onDownloadSuccess(download) {
        },
        onDownloadError(download) {
        },
        onDownloadProgress(download, downloadSize, totalSize) {
        },
    },
};

完整示例

示例代码

点击查看源码
vue

<template>
  <div class="es-sdk-root-css">
    <title class="es-sdk-content-title-css" :text="this.$options.name"/>
    <div class="es-sdk-content-divider-css"/>
    <div class="es-sdk-content-column-css">
      <div class="es-sdk-content-row-css">
        <text text="下载状态:"/>
        <text :text="downloadStatus"/>
        <text text="|"/>
        <text text="文件总长度:"/>
        <text :text="totalSize"/>
        <text text="|"/>
        <text text="下载文件长度:"/>
        <text :text="downloadSize"/>
      </div>
      <div class="es-sdk-content-row-css">
        <text-button text="初始化下载" @onButtonClicked="initDownloadModule"/>
        <text-button text="下载" @onButtonClicked="downloadFile"/>
        <text-button text="开始" @onButtonClicked="startDownload"/>
        <text-button text="停止" @onButtonClicked="stopDownload"/>
        <text-button text="取消" @onButtonClicked="cancelDownload"/>
      </div>
    </div>
  </div>
</template>

<script>
import {ESLog} from "@extscreen/es-log";
import {ESDownloadManager, ESDownload} from "@extscreen/es-downloader";
import {ESPage} from "@extscreen/es-core";

const TAG = "TEST_DOWNLOAD";
export default {
  name: '下载模块',
  mixins: [ESPage, ESDownload],
  data() {
    return {
      downloadSize: "0",
      totalSize: "0",
      downloadStatus: "",
      download: {
        id: "1",
        fileUrl: 'http://qcloudcdn-moss.cp47.ott.cibntv.net/project/tvq/qsj_video/2021/12/07/3800609_9c0bae6b6d5df502ffa28f9396a2316e.mp4',
        fileMD5: '6f6bc0aa03aeec7ae8cdf23edc511fcf',
        fileName: 'aaaa.mp4'
      }
    };
  },
  methods: {
    initDownloadModule() {
      ESDownloadManager.initDefault();
    },
    downloadFile() {
      ESDownloadManager.download(this.download)
    },
    startDownload() {
      ESDownloadManager.start(this.download)
    },
    stopDownload() {
      ESDownloadManager.stop(this.download)
    },
    cancelDownload() {
      ESDownloadManager.cancel(this.download)
    },
    onDownloadInit(download) {
      if (ESLog.isLoggable(ESLog.DEBUG)) {
        ESLog.d(TAG, "------onDownloadInit----->>>" + JSON.stringify(download))
      }
      this.downloadStatus = "下载初始化"
    },
    onDownloadStart(download) {
      if (ESLog.isLoggable(ESLog.DEBUG)) {
        ESLog.d(TAG, "------onDownloadStart----->>>" + JSON.stringify(download))
      }
      this.downloadStatus = "下载开始"
    },
    onDownloadStop(download) {
      if (ESLog.isLoggable(ESLog.DEBUG)) {
        ESLog.d(TAG, "------onDownloadStop----->>>" + JSON.stringify(download))
      }
      this.downloadStatus = "下载停止"
    },
    onDownloadCancel(download) {
      if (ESLog.isLoggable(ESLog.DEBUG)) {
        ESLog.d(TAG, "------onDownloadCancel----->>>" + JSON.stringify(download))
      }
      this.downloadStatus = "下载取消"
    },
    onDownloadSuccess(download) {
      if (ESLog.isLoggable(ESLog.DEBUG)) {
        ESLog.d(TAG, "------onDownloadSuccess----->>>" + JSON.stringify(download))
      }
      this.downloadStatus = "下载成功"
    },
    onDownloadError(download) {
      if (ESLog.isLoggable(ESLog.DEBUG)) {
        ESLog.d(TAG, "------onDownloadError----->>>" + JSON.stringify(download))
      }
      this.downloadStatus = "下载失败"
    },
    onDownloadProgress(download, downloadSize, totalSize) {
      this.downloadStatus = "正在下载"
      this.downloadSize = downloadSize + "";
      this.totalSize = totalSize + "";
      if (ESLog.isLoggable(ESLog.DEBUG)) {
        ESLog.d(TAG, "------onDownloadProgress----->>>"
            + JSON.stringify(download)
            + "---->>>downloadSize:" + downloadSize
            + "---->>>totalSize:" + totalSize
        )
      }
    },
  },
  components: {}
};
</script>

<style scoped>
</style>