177-371-24501(同微信)

微信小程序API音频播放控制,wx.playVoice?开始播放语音

2022-04-21 管理员

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)
  }
})
更多微信小程序开发教程,可以关注。
上一篇:微信小程序API背景音频播放管理,背景音频管理器backgroundAudioManager
下一篇:微信小程序API录音,wx.startRecord开始录音
相关资讯 Releva ntnews
解决方案 Solutions
相关热点 Hot spot
快速提升网站排名的方法
  1. 我们的优势
  2. 我们的实力
  3. 选择我们的理由
咨询电话(微信同号)

177-371-24501(同微信)

豫ICP备17049932号

Copyright © 2017-2022 版权所有 追风建站 Rights Reserved 技术支持:酷微科技

电话咨询 在线咨询 服务项目 SEO优化