# DownloadTask

更新时间:2024-07-23 11:06:59

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

# 方法

# DownloadTask.abort()

中断下载任务

# DownloadTask.onProgressUpdate(function callback)

监听下载进度变化事件

# DownloadTask.offProgressUpdate(function callback)

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

# 示例代码

const downloadTask = ks.downloadFile({  
  url: 'http://example.com/audio/123', //仅为示例,并非真实的资源  
  success (res) {  
    ks.playVoice({  
      filePath: res.tempFilePath  
    })  
  }  
})  
  
downloadTask.onProgressUpdate((res) => {  
  console.log('下载进度', res.progress)  
  console.log('已经下载的数据长度', res.totalBytesWritten)  
  console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)  
})  
  
downloadTask.abort() // 取消下载任务  
Copyright ©2025, All Rights Reserved