# 音频
# 一、接口
音频播放接口
- 使用 InnerAudioContext 播放
const audio = mogs.createInnerAudioContext()
audio.src = url // src 可以设置 http(s) 的路径,本地文件路径或者代码包文件路径
audio.play()
1
2
3
2
3
- 自动播放和循环播放
const bgm = mogs.createInnerAudioContext()
bgm.autoplay = true
bgm.loop = true
bgm.src = url
1
2
3
4
2
3
4
- 回到前台时恢复背景音乐
mogs.onShow(function () {
bgm.play()
})
1
2
3
2
3
- 处理音频中断事件
mogs.onAudioInterruptionEnd(function () {
bgm.play()
})
1
2
3
2
3
# 二、功能
- 微信小游戏
音频部分参考微信小游戏文档音频 (opens new window)
- QQ小游戏
音频部分参考QQ小游戏文档音频 (opens new window)
- 有乐小游戏