WeChat applet development documentation
/ 微信小程序API 音頻播放控制
微信小程序API 音頻播放控制
wx.playVoice(OBJECT)
開(kāi)始播放語(yǔ)音,同時(shí)只允許一個(gè)語(yǔ)音文件正在播放,如果前一個(gè)語(yǔ)音文件還沒(méi)播放完,將中斷前一個(gè)語(yǔ)音播放。
OBJECT參數(shù)說(shuō)明:
示例代碼:
wx.startRecord({ success:function(res){ var tempFilePath = res.tempFilePath; wx.playVoice({ filePath:tempFilePath, complete:function(){ } }) } })
wx.pauseVoice()
暫停正在播放的語(yǔ)音。再次調(diào)用wx.playVoice播放同一個(gè)文件時(shí),會(huì)從暫停處開(kāi)始播放。如果想從頭開(kāi)始播放,需要先調(diào)用wx.stopVoice
示例代碼:
wx.startRecord({ success:function(res){ var tempFilePath = res.tempFilePath; wx.playVoice({ filePath: tempFilePath }); setTimeout(function(){ //暫停播放 wx.pauseVoice() },5000) } });
wx.stopVoice()
結(jié)束播放語(yǔ)音
示例代碼:
wx.startRecord({ success:function(res){ var tempFilePath = res.tempFilePath; wx.playVoice({ filePath:tempFilePath }) setTimeout(function(){ wx.stopVoice(); },5000) } });