InnerAudioContext.onError(function callback)
监听音频播放错误事件
参数
function callback
音频播放错误事件的回调函数
参数
Object res
属性 | 类型 | 说明 |
---|---|---|
errMsg | string | |
errCode | number |
errCode 的合法值
值 | 说明 | 最低版本 |
---|---|---|
10001 | 系统错误 | |
10002 | 网络错误 | |
10003 | 文件错误 | |
10004 | 格式错误 | |
-1 | 未知错误 |
InnerAudioContext.onPause(function callback)
监听音频暂停事件
参数
function callback
音频暂停事件的回调函数
InnerAudioContext.onPlay(function callback)
监听音频播放事件
参数
function callback
音频播放事件的回调函数
InnerAudioContext.onSeeked(function callback)
监听音频完成跳转操作的事件
参数
function callback
音频完成跳转操作的事件的回调函数
InnerAudioContext.onSeeking(function callback)
监听音频进行跳转操作的事件
参数
function callback
音频进行跳转操作的事件的回调函数
InnerAudioContext.onStop(function callback)
监听音频停止事件
参数
function callback
音频停止事件的回调函数
InnerAudioContext.onTimeUpdate(function callback)
监听音频播放进度更新事件
参数
function callback
音频播放进度更新事件的回调函数
InnerAudioContext.onWaiting(function callback)
监听音频加载中事件。当音频因为数据不足,需要停下来加载时会触发
参数
function callback
音频加载中事件的回调函数
InnerAudioContext.pause()
暂停。暂停后的音频再播放会从暂停处开始播放
InnerAudioContext.play()
播放
InnerAudioContext.seek(number position)
跳转到指定位置
参数
number position
跳转的时间,单位 s。精确到小数点后 3 位,即支持 ms 级别精确度
InnerAudioContext.stop()
停止。停止后的音频再播放会从头开始播放。
支持格式
格式 | iOS | Android |
---|---|---|
flac | x | √ |
m4a | √ | √ |
ogg | x | √ |
ape | x | √ |
amr | x | √ |
wma | x | √ |
wav | √ | √ |
mp3 | √ | √ |
mp4 | x | √ |
aac | √ | √ |
aiff | √ | x |
caf | √ | x |
示例代码:
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)
})
标签:微信小程序
相关阅读 >>
更多相关阅读请进入《微信小程序》频道 >>
Vue.js 设计与实现 基于Vue.js 3 深入解析Vue.js 设计细节
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者