支持版本 >= 1.4.0
一个可以监听下载进度变化事件,以及取消下载任务的对象
中断下载任务
监听下载进度变化事件
const downloadTask = wx.downloadFile({
url: 'http://example.com/audio/123', //仅为示例,并非真实的资源
success (res) {
wx.playVoice({
filePath: res.tempFilePath
})
}
})
downloadTask.onProgressUpdate((res) => {
console.log('下载进度', res.progress)
console.log('已经下载的数据长度', res.totalBytesWritten)
console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
})
downloadTask.abort() // 取消下载任务