InnerAudioContext

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

属性

String src

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

Number startTime

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

Boolean autoplay

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

Boolean loop

是否循环播放,默认为 false

Boolean obeyMuteSwitch

是否遵循系统静音开关,默认为 true。当此参数为 false 时,即使用户打开了静音开关,也能继续发出声音。从 2.3.0 版本开始此参数不生效,使用 mc.setInnerAudioOption接口统一设置。

Number volume

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

Number playbackRate

播放速度。范围 0.5-2.0,默认为 1。(Android 需要 6 及以上版本)

Number duration

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

Number currentTime

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

Boolean paused

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

Number buffered

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

String referrerPolicy

origin: 发送完整的 referrer; no-referrer: 不发送。

方法

InnerAudioContext.play()

播放

InnerAudioContext.pause()

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

InnerAudioContext.stop()

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

InnerAudioContext.seek(Number currentTime)

跳转到指定位置

参数
参数 类型 默认值 必填 说明
currentTime Number 跳转到的时间位置,单位 s

InnerAudioContext.destroy()

事件

销毁当前实例

InnerAudioContext.onCanplay(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.offCanplay(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onPlay(Function callback)

监听音频播放事件

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.offPlay(Function callback)

取消监听音频播放事件

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onPause(Function callback)

监听音频暂停事件

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.offPause(Function callback)

取消监听音频暂停事件

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onStop(Function callback)

监听音频停止事件

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.offStop(Function callback)

取消监听音频停止事件

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onEnded(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.offEnded(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onTimeUpdate(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.onTimeUpdate.callback(Number time) | 参数 | 类型 | 说明 | | :-------------- | :----- | :-------------------- | | time | Number | 当前时间, 单位 s |

InnerAudioContext.offTimeUpdate(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onError(Function callback)

监听音频播放错误事件

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.onError.callback(Object res) | 属性 | 类型 | 说明 | | :-------------- | :----- | :-------------------- | | errMsg | String | 错误信息 | | errCode | Number | 错误码 |

Object.errCode | 值 | 说明 | | :-------------- |:-------------------- | | 10001 | 系统错误 | | 10002 | 网络错误 | | 10003 | 文件错误 | | 10004 | 格式错误 | | -1 | 未知错误 |

InnerAudioContext.offError(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onWaiting(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.offWaiting(Function callback)

取消监听音频加载中事件

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onSeeking(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.offSeeking(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

InnerAudioContext.onSeeked(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 监听回调函数

InnerAudioContext.offSeeked(Function callback)

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

参数
参数 类型 默认值 必填 说明
callback Function 需要取消的监听回调函数

results matching ""

    No results matching ""

    results matching ""

      No results matching ""