# qq.setInnerAudioOption

# qq.setInnerAudioOption(Object object)

设置 InnerAudioContext 的播放选项。设置之后对当前小程序全局生效。

# 参数

# Object object
属性 类型 默认值 必填 说明
mixWithOther boolean true 是否与其他音频混播,设置为 true 之后,不会终止其他应用或QQ内的音乐
obeyMuteSwitch boolean true (仅在 iOS 生效)是否遵循静音开关,设置为 false 之后,即使是在静音模式下,也能播放声音
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

# qq.getAvailableAudioSources

# qq.getAvailableAudioSources(Object object)

获取当前支持的音频输入源

# 参数

# Object object
属性 类型 默认值 必填 说明
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
# object.success 回调函数

参数

Object res

属性 类型 说明
audioSources Array.<string> 支持的音频输入源列表,可在 RecorderManager.start() 接口中使用。返回值定义参考 https://developer.android.com/reference/kotlin/android/media/MediaRecorder.AudioSource

res.audioSources 的合法值

说明
auto 自动设置,默认使用手机麦克风,插上耳麦后自动切换使用耳机麦克风,所有平台适用
buildInMic 手机麦克风,仅限 iOS
headsetMic 耳机麦克风,仅限 iOS
mic 麦克风(没插耳麦时是手机麦克风,插耳麦时是耳机麦克风),仅限 Android
camcorder 同 mic,适用于录制音视频内容,仅限 Android
voice_communication 同 mic,适用于实时沟通,仅限 Android
voice_recognition 同 mic,适用于语音识别,仅限 Android

# qq.createInnerAudioContext

# InnerAudioContext qq.createInnerAudioContext()

创建内部 audio 上下文 InnerAudioContext 对象。

# 返回值

# InnerAudioContext

# InnerAudioContext

InnerAudioContext 实例,可通过 qq.createInnerAudioContext 接口获取实例。

# 属性

# string src

音频资源的地址,用于直接播放。

# number startTime

开始播放的位置(单位:s),默认为 0

# boolean autoplay

是否自动开始播放,默认为 false

# boolean loop

是否循环播放,默认为 false

# number volume

音量。范围 0~1。默认为 1

# number duration

当前音频的长度(单位 s)。只有在当前有合法的 src 时返回(只读)

# number currentTime

当前音频的播放位置(单位 s)。只有在当前有合法的 src 时返回,时间保留小数点后 6 位(只读)

# boolean paused

当前是否是暂停或停止状态(只读)

# number buffered

音频缓冲的时间点,仅保证当前播放时间点到此时间点内容已缓冲(只读)

# 方法

# InnerAudioContext.play()

播放

# InnerAudioContext.pause()

暂停。暂停后的音频再播放会从暂停处开始播放

# InnerAudioContext.stop()

停止。停止后的音频再播放会从头开始播放。

# InnerAudioContext.seek(number position)

跳转到指定位置

# InnerAudioContext.destroy()

销毁当前实例

# InnerAudioContext.onCanplay(function callback)

监听音频进入可以播放状态的事件。但不保证后面可以流畅播放

# InnerAudioContext.offCanplay(function callback)

取消监听音频进入可以播放状态的事件

# InnerAudioContext.onPlay(function callback)

监听音频播放事件

# InnerAudioContext.offPlay(function callback)

取消监听音频播放事件

# InnerAudioContext.onPause(function callback)

监听音频暂停事件

# InnerAudioContext.offPause(function callback)

取消监听音频暂停事件

# InnerAudioContext.onStop(function callback)

监听音频停止事件

# InnerAudioContext.offStop(function callback)

取消监听音频停止事件

# InnerAudioContext.onEnded(function callback)

监听音频自然播放至结束的事件

# InnerAudioContext.offEnded(function callback)

取消监听音频自然播放至结束的事件

# InnerAudioContext.onTimeUpdate(function callback)

监听音频播放进度更新事件

# InnerAudioContext.offTimeUpdate(function callback)

取消监听音频播放进度更新事件

# InnerAudioContext.onError(function callback)

监听音频播放错误事件

# InnerAudioContext.offError(function callback)

取消监听音频播放错误事件

# InnerAudioContext.onWaiting(function callback)

监听音频加载中事件。当音频因为数据不足,需要停下来加载时会触发

# InnerAudioContext.offWaiting(function callback)

取消监听音频加载中事件

# InnerAudioContext.onSeeking(function callback)

监听音频进行跳转操作的事件

# InnerAudioContext.offSeeking(function callback)

取消监听音频进行跳转操作的事件

# InnerAudioContext.onSeeked(function callback)

监听音频完成跳转操作的事件

# InnerAudioContext.offSeeked(function callback)

取消监听音频完成跳转操作的事件

# 支持格式

格式 iOS Android
flac x
m4a
ogg x
ape x
amr x
wma x
wav
mp3
mp4 x
aac
aiff x
caf x

# 示例代码

const innerAudioContext = qq.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)
})
1
2
3
4
5
6
7
8
9
10

# .destroy

# InnerAudioContext.destroy()

销毁当前实例

# .offCanplay

# InnerAudioContext.offCanplay(function callback)

取消监听音频进入可以播放状态的事件

# 参数

# function callback

音频进入可以播放状态的事件的回调函数

# .offEnded

# InnerAudioContext.offEnded(function callback)

取消监听音频自然播放至结束的事件

# 参数

# function callback

音频自然播放至结束的事件的回调函数

# .offError

# InnerAudioContext.offError(function callback)

取消监听音频播放错误事件

# 参数

# function callback

音频播放错误事件的回调函数

# .offPause

# InnerAudioContext.offPause(function callback)

取消监听音频暂停事件

# 参数

# function callback

音频暂停事件的回调函数

# .offPlay

# InnerAudioContext.offPlay(function callback)

取消监听音频播放事件

# 参数

# function callback

音频播放事件的回调函数

# .offSeeked

# InnerAudioContext.offSeeked(function callback)

取消监听音频完成跳转操作的事件

# 参数

# function callback

音频完成跳转操作的事件的回调函数

# .offSeeking

# InnerAudioContext.offSeeking(function callback)

取消监听音频进行跳转操作的事件

# 参数

# function callback

音频进行跳转操作的事件的回调函数

# .offStop

# InnerAudioContext.offStop(function callback)

取消监听音频停止事件

# 参数

# function callback

音频停止事件的回调函数

# .offTimeUpdate

# InnerAudioContext.offTimeUpdate(function callback)

取消监听音频播放进度更新事件

# 参数

# function callback

音频播放进度更新事件的回调函数

# .offWaiting

# InnerAudioContext.offWaiting(function callback)

取消监听音频加载中事件

# 参数

# function callback

音频加载中事件的回调函数

# .onCanplay

# InnerAudioContext.onCanplay(function callback)

监听音频进入可以播放状态的事件。但不保证后面可以流畅播放

# 参数

# function callback

音频进入可以播放状态的事件的回调函数

# .onEnded

# InnerAudioContext.onEnded(function callback)

监听音频自然播放至结束的事件

# 参数

# function callback

音频自然播放至结束的事件的回调函数

# .onError

# InnerAudioContext.onError(function callback)

监听音频播放错误事件

# 参数

# function callback

音频播放错误事件的回调函数

# 参数

Object res

属性 类型 说明
errCode number

errCode 的合法值

说明
10001 系统错误
10002 网络错误
10003 文件错误
10004 格式错误
-1 未知错误

# .onPause

# InnerAudioContext.onPause(function callback)

监听音频暂停事件

# 参数

# function callback

音频暂停事件的回调函数

# .onPlay

# InnerAudioContext.onPlay(function callback)

监听音频播放事件

# 参数

# function callback

音频播放事件的回调函数

# .onSeeked

# InnerAudioContext.onSeeked(function callback)

监听音频完成跳转操作的事件

# 参数

# function callback

音频完成跳转操作的事件的回调函数

# .onSeeking

# InnerAudioContext.onSeeking(function callback)

监听音频进行跳转操作的事件

# 参数

# function callback

音频进行跳转操作的事件的回调函数

# .onStop

# InnerAudioContext.onStop(function callback)

监听音频停止事件

# 参数

# function callback

音频停止事件的回调函数

# .onTimeUpdate

# InnerAudioContext.onTimeUpdate(function callback)

监听音频播放进度更新事件

# 参数

# function callback

音频播放进度更新事件的回调函数

# .onWaiting

# InnerAudioContext.onWaiting(function callback)

监听音频加载中事件。当音频因为数据不足,需要停下来加载时会触发

# 参数

# function callback

音频加载中事件的回调函数

# .pause

# InnerAudioContext.pause()

暂停。暂停后的音频再播放会从暂停处开始播放

# .play

# InnerAudioContext.play()

播放

# .seek

# InnerAudioContext.seek(number position)

跳转到指定位置

# 参数

# number position

跳转的时间,单位 s。精确到小数点后 3 位,即支持 ms 级别精确度

# .stop

# InnerAudioContext.stop()

停止。停止后的音频再播放会从头开始播放。