媒体组件audio
微信小程序中音频的使用还算是较常用.
audio
- 可以播放在线音频资源
支持的属性:
- 参考https://developers.weixin.qq.com/miniprogram/dev/component/audio.html
wx.createInnerAudioContext 接口
-
1.6.0版本开始,audio组件不再维护
-
InnerAudioContext wx.createInnerAudioContext(Object object)
创建内部 audio 上下文 InnerAudioContext 对象。 -
使用时,在获取到对象后,以属性的方式进行操作
属性
- 参考:https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/InnerAudioContext.html
方法
const innerAudioContext = wx.createInnerAudioContext()
innerAudioContext.autoplay = true
innerAudioContext.src = 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46'
innerAudioContext.onPlay(() => {
console.log('开始播放')
})
innerAudioContext.onError((res) => {
console.log(res.errMsg)
console.log(res.errCode)
})