# InnerAudioContext
内部音频上下文,通过 mt.createInnerAudioContext() 创建。
# 支持情况
| 项 | 说明 |
|---|---|
| 兼容性 | 兼容微信 |
# 属性
| 属性 | 类型 | 读写 | 说明 |
|---|---|---|---|
| src | string | 读写 | 音频资源地址,支持本地路径和网络 URL;赋值后自动准备播放 |
| startTime | number | 读写 | 开始播放的位置,单位秒,默认 0 |
| autoplay | boolean | 读写 | 是否自动播放,默认 false |
| loop | boolean | 读写 | 是否循环播放,默认 false |
| obeyMuteSwitch | boolean | 读写 | 是否遵循系统静音开关,默认 true |
| volume | number | 读写 | 音量,范围 0~1,默认 1 |
| paused | boolean | 只读 | 当前是否暂停,默认 true |
| duration | number | 只读 | 音频总时长,单位秒;在 onCanplay 触发后才有值 |
| currentTime | number | 只读 | 当前播放位置,单位秒 |
| buffered | number | 只读 | 已缓冲到的位置,单位秒 |
# 方法
| 方法 | 说明 |
|---|---|
| InnerAudioContext.play() | 播放 |
| InnerAudioContext.pause() | 暂停 |
| InnerAudioContext.stop() | 停止,currentTime 归零 |
| InnerAudioContext.seek() | 跳转到指定位置 |
| InnerAudioContext.destroy() | 销毁实例,释放资源 |
# 事件
| 方法 | 说明 |
|---|---|
| InnerAudioContext.onCanplay() | 监听音频可以播放事件 |
| InnerAudioContext.offCanplay() | 移除可播放监听 |
| InnerAudioContext.onPlay() | 监听播放事件 |
| InnerAudioContext.offPlay() | 移除播放监听 |
| InnerAudioContext.onPause() | 监听暂停事件 |
| InnerAudioContext.offPause() | 移除暂停监听 |
| InnerAudioContext.onStop() | 监听停止事件 |
| InnerAudioContext.offStop() | 移除停止监听 |
| InnerAudioContext.onEnded() | 监听自然播放结束事件 |
| InnerAudioContext.offEnded() | 移除结束监听 |
| InnerAudioContext.onTimeUpdate() | 监听播放进度更新事件 |
| InnerAudioContext.offTimeUpdate() | 移除进度监听 |
| InnerAudioContext.onError() | 监听错误事件 |
| InnerAudioContext.offError() | 移除错误监听 |
| InnerAudioContext.onWaiting() | 监听音频加载中事件 |
| InnerAudioContext.offWaiting() | 移除加载中监听 |
| InnerAudioContext.onSeeking() | 监听 seek 操作开始事件 |
| InnerAudioContext.offSeeking() | 移除 seek 开始监听 |
| InnerAudioContext.onSeeked() | 监听 seek 操作完成事件 |
| InnerAudioContext.offSeeked() | 移除 seek 完成监听 |
# 与微信差异
- 不支持微信的
playbackRate属性(播放速率),播放速率固定为1。