Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API audio start playing


May 18, 2021 WeChat Mini Program Development Document


Table of contents


wx.playVoice(Object object)

Starting with base library 1.6.0, this interface is no 10th stop maintenance, please use wx.createInnerAudioContext instead

Start playing the voice. Only one voice file is allowed to play at the same time, and if the previous voice file is not finished, the previous voice playback is interrupted.

Parameters

Object object

Property Type The default Required Description The lowest version
filePath string Is File path for voice files that need to be played (local path)
duration number 60 Whether Specify the recording time, reach the specified recording length and automatically stop recording in seconds 1.6.0
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

The sample code

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