微信小程式開發(fā)文檔
/ 微信小程序API 音頻播放控制
微信小程序API 音頻播放控制
wx.playVoice(OBJECT)
開始播放語音,同時只允許一個語音文件正在播放,如果前一個語音文件還沒播放完,將中斷前一個語音播放。
OBJECT參數(shù)說明:
示例代碼:
wx.startRecord({ success:function(res){ var tempFilePath = res.tempFilePath; wx.playVoice({ filePath:tempFilePath, complete:function(){ } }) } })
wx.pauseVoice()
暫停正在播放的語音。再次調(diào)用wx.playVoice播放同一個文件時,會從暫停處開始播放。如果想從頭開始播放,需要先調(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é)束播放語音
示例代碼:
wx.startRecord({ success:function(res){ var tempFilePath = res.tempFilePath; wx.playVoice({ filePath:tempFilePath }) setTimeout(function(){ wx.stopVoice(); },5000) } });