跳转至

js_player

Class Summary

AudioModule

音频播放器 JS 模块封装类,提供音频播放控制与属性访问接口

PlayerInterruptListener

音频中断事件监听器,处理音频中断通知

  • 构造:无
  • 成员函数

    接口名称 功能简述
    OnInterrupt 音频中断事件回调
  • 使用包含头文件#include "audio_module.h"

  • 声明头文件middleware/services/media/foundation/player/interfaces/kits/player_lite/js/builtin/include/audio_module.h
  • 公有运算符:无
  • 继承关系:Audio::InterruptListener
  • 嵌套类型:无
  • 模板形参:无

Functions

自由函数

InitAudioModule

void InitAudioModule(JSIValue exports)

功能说明

  • 注册音频播放器模块到 JS 运行时环境,将播放器相关接口导出到 exports 对象
  • 在 JS 应用启动时调用,完成音频播放模块的初始化与接口绑定
  • 调用后 JS 层可通过导出对象访问音频播放器的全部能力

入参

名称 参数类型 详细说明 约束取值范围
exports JSIValue JS 导出对象,模块接口将绑定到该对象上 有效的 JSIValue 对象

AudioModule

SetVolume

static bool SetVolume(float volume)

功能说明

  • 设置音频播放器的全局音量
  • 音量值为浮点数,调用后立即生效
  • 该方法为静态方法,无需对象实例即可调用

入参

名称 参数类型 详细说明 约束取值范围
volume float 目标音量值 0.0 ~ 1.0

返回值

  • 返回类型:bool

返回音量设置结果

返回值 触发场景
true 音量设置成功
false 音量设置失败

OnTerminate

static void OnTerminate()

功能说明

  • 在模块终止时执行清理操作,释放模块持有的资源
  • 该方法为静态方法,由框架在模块卸载时调用
  • 调用后模块不再可用,应停止所有播放操作

DefineProperty

static void DefineProperty(JSIValue target, const char * propName, JSIFunctionHandler getter, JSIFunctionHandler setter)

功能说明

  • 在指定 JS 对象上定义属性访问器,绑定 getter 与 setter 回调函数
  • 用于将 C++ 层属性读写逻辑映射为 JS 属性访问接口
  • 该方法为静态方法,在模块初始化阶段用于注册属性

入参

名称 参数类型 详细说明 约束取值范围
target JSIValue 目标 JS 对象 有效的 JSIValue 对象
propName const char * 属性名称字符串 非空字符串
getter JSIFunctionHandler 属性读取回调函数 有效的回调函数
setter JSIFunctionHandler 属性写入回调函数 有效的回调函数

Play

static JSIValue Play(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 启动音频播放,从当前源地址开始播放音频
  • 该方法为静态方法,作为 JS 层播放接口的底层实现
  • 播放启动后可通过 OnPlay 回调获知播放状态变化

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回播放操作结果

返回值 触发场景
0 播放启动成功
非0 播放启动失败

Pause

static JSIValue Pause(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 暂停当前正在播放的音频
  • 该方法为静态方法,作为 JS 层暂停接口的底层实现
  • 暂停后可调用 Play 恢复播放

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回暂停操作结果

返回值 触发场景
0 暂停成功
非0 暂停失败

Stop

static JSIValue Stop(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 停止音频播放,释放播放资源
  • 该方法为静态方法,作为 JS 层停止接口的底层实现
  • 停止后播放位置重置,需重新调用 Play 播放

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回停止操作结果

返回值 触发场景
0 停止成功
非0 停止失败

Reset

static JSIValue Reset(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 重置播放器状态,恢复到初始状态
  • 该方法为静态方法,作为 JS 层重置接口的底层实现
  • 重置后播放进度、源地址等属性恢复默认值

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回重置操作结果

返回值 触发场景
0 重置成功
非0 重置失败

GetPlayState

static JSIValue GetPlayState(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取当前播放器状态
  • 该方法为静态方法,作为 JS 层状态查询接口的底层实现
  • 返回值表示当前播放状态

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回当前播放状态

返回值 触发场景
0 空闲状态
非0 播放中/暂停/停止等其他状态

SrcGetter

static JSIValue SrcGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取音频源地址属性值
  • 该方法为静态方法,作为 JS 层 src 属性读取回调的底层实现
  • 返回当前设置的音频源地址

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

SrcInnerGetter

static JSIValue SrcInnerGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取内部音频源地址属性值
  • 该方法为静态方法,作为 JS 层内部 src 属性读取回调的底层实现
  • 与 SrcGetter 区别在于访问内部源地址

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

SrcSetter

static JSIValue SrcSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置音频源地址属性值
  • 该方法为静态方法,作为 JS 层 src 属性写入回调的底层实现
  • 设置后播放器将从指定源地址加载音频

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含源地址参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

SetSrcList

static JSIValue SetSrcList(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置音频源地址列表,支持多源播放
  • 该方法为静态方法,作为 JS 层设置源列表接口的底层实现
  • 设置后播放器将按列表顺序播放

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含源列表参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

SrcInnerSetter

static JSIValue SrcInnerSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置内部音频源地址属性值
  • 该方法为静态方法,作为 JS 层内部 src 属性写入回调的底层实现
  • 与 SrcSetter 区别在于设置内部源地址

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含源地址参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

CurrentTimeGetter

static JSIValue CurrentTimeGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取当前播放时间位置
  • 该方法为静态方法,作为 JS 层 currentTime 属性读取回调的底层实现
  • 返回当前播放进度的时间值

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

CurrentTimeSetter

static JSIValue CurrentTimeSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置当前播放时间位置,实现播放跳转
  • 该方法为静态方法,作为 JS 层 currentTime 属性写入回调的底层实现
  • 设置后播放器将跳转到指定时间位置

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含目标时间参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

DurationGetter

static JSIValue DurationGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取音频总时长
  • 该方法为静态方法,作为 JS 层 duration 属性读取回调的底层实现
  • 返回当前音频的总时长值

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

DurationSetter

static JSIValue DurationSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置音频总时长属性值
  • 该方法为静态方法,作为 JS 层 duration 属性写入回调的底层实现
  • 用于更新音频总时长信息

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含时长参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

AutoPlayGetter

static JSIValue AutoPlayGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取自动播放属性值
  • 该方法为静态方法,作为 JS 层 autoplay 属性读取回调的底层实现
  • 返回当前自动播放是否启用

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

AutoPlaySetter

static JSIValue AutoPlaySetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置自动播放属性,控制源地址加载后是否自动开始播放
  • 该方法为静态方法,作为 JS 层 autoplay 属性写入回调的底层实现
  • 设置为启用后,设置源地址时将自动触发播放

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含自动播放开关参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

LoopGetter

static JSIValue LoopGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取循环播放属性值
  • 该方法为静态方法,作为 JS 层 loop 属性读取回调的底层实现
  • 返回当前循环播放是否启用

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

LoopSetter

static JSIValue LoopSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置循环播放属性,控制播放结束后是否自动重新播放
  • 该方法为静态方法,作为 JS 层 loop 属性写入回调的底层实现
  • 设置为启用后,音频播放结束将自动从头开始

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含循环播放开关参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

VolumeGetter

static JSIValue VolumeGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取当前音量属性值
  • 该方法为静态方法,作为 JS 层 volume 属性读取回调的底层实现
  • 返回当前实例的音量值

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

VolumeSetter

static JSIValue VolumeSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置当前实例的音量属性值
  • 该方法为静态方法,作为 JS 层 volume 属性写入回调的底层实现
  • 设置后立即生效,影响当前播放音频的音量

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含音量值参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

MutedGetter

static JSIValue MutedGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取静音属性值
  • 该方法为静态方法,作为 JS 层 muted 属性读取回调的底层实现
  • 返回当前是否处于静音状态

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

MutedSetter

static JSIValue MutedSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置静音属性,控制音频输出是否静音
  • 该方法为静态方法,作为 JS 层 muted 属性写入回调的底层实现
  • 静音后音频继续播放但不输出声音

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含静音开关参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

OnPlayGetter

static JSIValue OnPlayGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取播放事件回调函数
  • 该方法为静态方法,作为 JS 层 onplay 属性读取回调的底层实现
  • 返回当前注册的播放事件回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

OnPlaySetter

static JSIValue OnPlaySetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置播放事件回调函数,音频开始播放时触发该回调
  • 该方法为静态方法,作为 JS 层 onplay 属性写入回调的底层实现
  • 设置后当播放状态变为播放中将调用注册的回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含回调函数参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

OnPauseGetter

static JSIValue OnPauseGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取暂停事件回调函数
  • 该方法为静态方法,作为 JS 层 onpause 属性读取回调的底层实现
  • 返回当前注册的暂停事件回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

OnPauseSetter

static JSIValue OnPauseSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置暂停事件回调函数,音频暂停时触发该回调
  • 该方法为静态方法,作为 JS 层 onpause 属性写入回调的底层实现
  • 设置后当播放状态变为暂停将调用注册的回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含回调函数参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

OnStopGetter

static JSIValue OnStopGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取停止事件回调函数
  • 该方法为静态方法,作为 JS 层 onstop 属性读取回调的底层实现
  • 返回当前注册的停止事件回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

OnStopSetter

static JSIValue OnStopSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置停止事件回调函数,音频停止时触发该回调
  • 该方法为静态方法,作为 JS 层 onstop 属性写入回调的底层实现
  • 设置后当播放器停止播放将调用注册的回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含回调函数参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

OnLoadedDataGetter

static JSIValue OnLoadedDataGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取数据加载完成事件回调函数
  • 该方法为静态方法,作为 JS 层 onloadeddata 属性读取回调的底层实现
  • 返回当前注册的数据加载完成事件回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

OnLoadedDataSetter

static JSIValue OnLoadedDataSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置数据加载完成事件回调函数,音频数据加载完成时触发
  • 该方法为静态方法,作为 JS 层 onloadeddata 属性写入回调的底层实现
  • 设置后当音频数据加载完成将调用注册的回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含回调函数参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

OnEndedGetter

static JSIValue OnEndedGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取播放结束事件回调函数
  • 该方法为静态方法,作为 JS 层 onended 属性读取回调的底层实现
  • 返回当前注册的播放结束事件回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

OnEndedSetter

static JSIValue OnEndedSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置播放结束事件回调函数,音频播放到末尾时触发
  • 该方法为静态方法,作为 JS 层 onended 属性写入回调的底层实现
  • 设置后当音频播放完毕将调用注册的回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含回调函数参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

OnErrorGetter

static JSIValue OnErrorGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取错误事件回调函数
  • 该方法为静态方法,作为 JS 层 onerror 属性读取回调的底层实现
  • 返回当前注册的错误事件回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

OnErrorSetter

static JSIValue OnErrorSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置错误事件回调函数,播放过程中发生错误时触发
  • 该方法为静态方法,作为 JS 层 onerror 属性写入回调的底层实现
  • 设置后当播放出现错误将调用注册的回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含回调函数参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

OnTimeUpdateGetter

static JSIValue OnTimeUpdateGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取时间更新事件回调函数
  • 该方法为静态方法,作为 JS 层 ontimeupdate 属性读取回调的底层实现
  • 返回当前注册的时间更新事件回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

OnTimeUpdateSetter

static JSIValue OnTimeUpdateSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置时间更新事件回调函数,播放过程中时间变化时触发
  • 该方法为静态方法,作为 JS 层 ontimeupdate 属性写入回调的底层实现
  • 设置后播放过程中时间位置变化将调用注册的回调

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含回调函数参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

StreamTypeGetter

static JSIValue StreamTypeGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取音频流类型属性值
  • 该方法为静态方法,作为 JS 层 streamType 属性读取回调的底层实现
  • 返回当前音频流类型

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

StreamTypeSetter

static JSIValue StreamTypeSetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置音频流类型属性,指定音频输出流类别
  • 该方法为静态方法,作为 JS 层 streamType 属性写入回调的底层实现
  • 设置后音频将按指定流类型进行输出

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含流类型参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

BackgroundPlaySetter

static JSIValue BackgroundPlaySetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置后台播放属性,控制应用进入后台后是否继续播放音频
  • 该方法为静态方法,作为 JS 层 backgroundPlay 属性写入回调的底层实现
  • 设置为启用后,应用切到后台时音频不会暂停

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含后台播放开关参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

BackgroundPlayGetter

static JSIValue BackgroundPlayGetter(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取后台播放属性值
  • 该方法为静态方法,作为 JS 层 backgroundPlay 属性读取回调的底层实现
  • 返回当前后台播放是否启用

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

GetAlbumInfo

static JSIValue GetAlbumInfo(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 获取当前播放音频的专辑信息
  • 该方法为静态方法,作为 JS 层获取专辑信息接口的底层实现
  • 返回包含专辑名称、艺术家等元数据信息

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回获取操作结果

返回值 触发场景
0 获取成功
非0 获取失败

SetQuitTime

static JSIValue SetQuitTime(const JSIValue thisVal, const JSIValue * args, uint8_t argsSize)

功能说明

  • 设置退出时间,控制播放器在指定时间后自动退出
  • 该方法为静态方法,作为 JS 层设置退出时间接口的底层实现
  • 设置后播放器到达指定时间将触发退出流程

入参

名称 参数类型 详细说明 约束取值范围
thisVal const JSIValue JS this 对象 有效的 JSIValue 对象
args const JSIValue * 参数列表指针,含退出时间参数 非空指针
argsSize uint8_t 参数数量 0 ~ 255

返回值

  • 返回类型:JSIValue

返回设置操作结果

返回值 触发场景
0 设置成功
非0 设置失败

PlayerInterruptListener

OnInterrupt

void OnInterrupt(int32_t type, int32_t hint)

功能说明

  • 音频中断事件回调,当音频播放被系统中断时触发
  • 该方法继承自 Audio::InterruptListener 基类,覆写中断处理逻辑
  • 中断类型和提示信息由音频系统传入,用于区分中断原因

入参

名称 参数类型 详细说明 约束取值范围
type int32_t 中断类型,表示中断的类别 音频系统定义的中断类型值
hint int32_t 中断提示,表示中断的响应建议 音频系统定义的中断提示值