DownloadTask

一个可以监听下载进度变化事件,以及取消下载任务的对象

方法

DownloadTask.abort()

中断下载任务

DownloadTask.onProgressUpdate(Function callback)

监听下载进度变化事件

参数
参数 类型 默认值 必填 说明
callback Function 进度回调

DownloadTask.onProgressUpdate.callback 回调参数

属性 类型 说明
progress Number 下载进度百分比
totalBytesWritten Number 已经下载的数据长度,单位 Bytes
totalBytesExpectedToWrite Number 预期需要下载的数据总长度,单位 Bytes

DownloadTask.offProgressUpdate(Function callback)

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听函数

取消监听下载进度变化事件

示例代码:

const downloadTask = mc.downloadFile({
  url: 'http://test.com/',
  success (res) {
    console.log(res.tempFilePath)
  }
})

downloadTask.onProgressUpdate((res) => {
  console.log('下载进度', res.progress)
  console.log('已经下载的数据长度', res.totalBytesWritten)
  console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
})

downloadTask.abort() // 取消下载任务

results matching ""

    No results matching ""

    results matching ""

      No results matching ""