首页 开发文档 媒体

微信小程序API 音频播放控制

微信小程序API 音频播放控制

上传时间:2018-05-01阅读数:1911

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)
  }
})
意见反馈 回到顶部
咨询帮助
咨询帮助
微信公众号
微信公众号