本文編輯: 大妖怪瀏覽 2789
版權(quán)所有,嚴(yán)禁轉(zhuǎn)載
接口 | 說明 |
---|---|
wx.createAudioContext | 創(chuàng)建并返回 audio 上下文 audioContext 對象 |
wxml
<audio src="{{src}}" id="myAudio" ></audio>
<button type="primary" bindtap="audioPlay">播放</button>
<button type="primary" bindtap="audioPause">暫停</button>
<button type="primary" bindtap="audio14">設(shè)置當(dāng)前播放時(shí)間為14秒</button>
<button type="primary" bindtap="audioStart">回到開頭</button>
js
Page({
onReady: function (e) {
// 使用 wx.createAudioContext 獲取 audio 上下文 context
this.audioCtx = wx.createAudioContext('myAudio')
this.audioCtx.setSrc('http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E06DCBDC9AB7C49FD713D632D313AC4858BACB8DDD29067D3C601481D36E62053BF8DFEAF74C0A5CCFADD6471160CAF3E6A&fromtag=46')
this.audioCtx.play()
},
data: {
src: ''
},
audioPlay: function () {
this.audioCtx.play()
console.log("開始播放成功");
},
audioPause: function () {
this.audioCtx.pause()
console.log("暫停播放成功");
},
audio14: function () {
this.audioCtx.seek(14)
console.log("從從14秒開始播放成功");
},
audioStart: function () {
this.audioCtx.seek(0)
console.log("從頭開始播放成功");
}
})
【audioContext】:【audioContext 通過 audioId 跟一個(gè) 組件綁定,通過它可以操作對應(yīng)的 組件】
參數(shù) | 參數(shù) | 描述 |
---|---|---|
setSrc | src | 音頻的地址 |
play | 無 | 播放 |
pause | 無 | 暫停 |
seek | position | 跳轉(zhuǎn)到指定位置,單位 s |