播放不了已经下载成功的临时文件,Why?
发布于 6 年前 作者 fang72 5496 次浏览 来自 问答
downloadFile : function(){
    var that = this;
    const downloadTask = wx.downloadFile({
      url: 'http://mp3.flash127.com/Uploads/201708/20170810_1819_170614.mp3',
      success: function(res){
        wx.playVoice({
            filePath: res.tempFilePath,
            success : function(res){
                console.log(res);
            },
            fail : function(){
                console.log("Error!");
            },
            complete : function(){}
        });
      },
      fail : function(){
        console.log("Error!");
      },
      complete : function(){}
  });
    downloadTask.onProgressUpdate((res) => {
        that.setData({
            downloadFileProgress: res.progress
        });
        console.log('下载进度', res.progress)
        console.log('已经下载的数据长度', res.totalBytesWritten)
        console.log('预期需要下载的数据总长度', res.totalBytesExpectedToWrite)
    });
    //downloadTask.abort();
}
2 回复

同问

function play(url) {

    wx.playBackgroundAudio({

        dataUrl: url

    });

    console.log(url);

    wx.onBackgroundAudioStop(function () {

        wx.playBackgroundAudio({

            dataUrl: url

        });

    });

}

下载的临时文件不能播放?

我在console里面打出来点击链接可以播放,但是调用play方法不能播放

playVoice 只能播放录音文件

回到顶部