wx.playVoice(OBJECT)
 开始播放语音,同时只允许一个语音文件正在播放,如果前一个语音文件还没播放完,将中断前一个语音播放。
OBJECT参数说明:
| 参数 | 类型 | 必填 | 说明 | 
|---|---|---|---|
| filePath | String | 是 | 需要播放的语音文件的文件路径 | 
| success | Function | 否 | 接口调用成功的回调函数 | 
| fail | Function | 否 | 接口调用失败的回调函数 | 
| complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | 
示例代码:
wx.startRecord({
  success:function(res){
    var tempFilePath = res.tempFilePath;
    wx.playVoice({
      filePath:tempFilePath,
      complete:function(){
      } 
    })
  }
})                                    wx.pauseVoice()
 暂停正在播放的语音。再次调用wx.playVoice播放同一个文件时,会从暂停处开始播放。如果想从头开始播放,需要先调用wx.stopVoice
示例代码:
wx.startRecord({
  success:function(res){
    var tempFilePath = res.tempFilePath;
      wx.playVoice({
      filePath: tempFilePath
    });
    setTimeout(function(){
        //暂停播放
      wx.pauseVoice()
    },5000)
  }
});                                    wx.stopVoice()
 结束播放语音
示例代码:
wx.startRecord({
  success:function(res){
    var tempFilePath = res.tempFilePath;
    wx.playVoice({
      filePath:tempFilePath
    })
    setTimeout(function(){
      wx.stopVoice();
    },5000)
  }
});