WeChat Open Platform

Mini Programs Documentation

Audio Controls

wx.playVoice(OBJECT)

Starts playing voice message. Only one voice message file is permitted to be played at the same time, the previous voice message file will be interrupted if it hasn't finished playing.

OBJECT parameter descriptions:

Parameter Type Required Description
filePath String Yes File path for voice message file to be played
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

Sample code:

wx.startRecord({
  success: function(res) {
    var tempFilePath = res.tempFilePath
    wx.playVoice({
      filePath: tempFilePath,
      complete: function(){
      }
    })
  }
})

wx.pauseVoice()

Pauses the voice message that is playing. If wx.playVoice is called again to play the same file, it will start playing from the place where it was paused. If you want to start playing from the beginning, you need to call wx.stopVoice first.

Sample code:

wx.startRecord({
  success: function(res) {
    var tempFilePath = res.tempFilePath
      wx.playVoice({
      filePath: tempFilePath
    })

    setTimeout(function() {
        //Pause
      wx.pauseVoice()
    }, 5000)
  }
})

wx.stopVoice()

Stop playing voice message.

Sample code:

wx.startRecord({
  success: function(res) {
    var tempFilePath = res.tempFilePath
    wx.playVoice({
      filePath:tempFilePath
    })

    setTimeout(function(){
      wx.stopVoice()
    }, 5000)
  }
})