diff --git a/zh-cn/application-dev/reference/apis/js-apis-avsession.md b/zh-cn/application-dev/reference/apis/js-apis-avsession.md index 7f4c5661939d5a68f119953cf3b37553b16a6d09..0deca790f529118ebd83c15c966aaccd7b4d0c63 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-avsession.md +++ b/zh-cn/application-dev/reference/apis/js-apis-avsession.md @@ -53,13 +53,13 @@ createAVSession(context: Context, tag: string, type: AVSessionType): Promise\ { - session = data; - console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); + currentAVSession = data; + console.info(`CreateAVSession : SUCCESS : sessionId = ${currentAVSession.sessionId}`); }).catch((err) => { console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); }); @@ -95,7 +95,7 @@ createAVSession(context: Context, tag: string, type: AVSessionType, callback: As ```js import featureAbility from '@ohos.ability.featureAbility'; -let session; +let currentAVSession; let tag = "createNewSession"; let context = featureAbility.getContext(); @@ -103,7 +103,7 @@ avSession.createAVSession(context, tag, "audio", function (err, data) { if (err) { console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); } else { - session = data; + currentAVSession = data; console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); } }); @@ -145,7 +145,7 @@ avSession.getAllSessionDescriptors().then((descriptors) => { console.info(`GetAllSessionDescriptors : SUCCESS : descriptors[0].sessionTag : ${descriptors[0].sessionTag}`); } }).catch((err) => { - console.info(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetAllSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -180,7 +180,7 @@ getAllSessionDescriptors(callback: AsyncCallback\ 0 ){ @@ -237,7 +237,7 @@ avSession.getHistoricalSessionDescriptors().then((descriptors) => { console.info(`getHistoricalSessionDescriptors : SUCCESS : descriptors[0].elementName.bundleName : ${descriptors[0].elementName.bundleName}`); } }).catch((err) => { - console.info(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`getHistoricalSessionDescriptors BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -273,7 +273,7 @@ getHistoricalSessionDescriptors(maxSize: number, callback: AsyncCallback\ 0 ){ @@ -323,25 +323,13 @@ createController(sessionId: string): Promise\ **示例:** ```js -import featureAbility from '@ohos.ability.featureAbility'; - -let session; -let tag = "createNewSession"; -let context = featureAbility.getContext(); - -await avSession.createAVSession(context, tag, "audio").then((data) => { - session = data; - console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); -}).catch((err) => { - console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); -}); -let controller; -await avSession.createController(session.sessionId).then((avcontroller) => { - controller = avcontroller; - console.info(`CreateController : SUCCESS : ${controller.sessionId}`); +let currentAVcontroller; +await avSession.createController(currentAVSession.sessionId).then((avcontroller) => { + currentAVcontroller = avcontroller; + console.info(`CreateController : SUCCESS : ${currentAVcontroller.sessionId}`); }).catch((err) => { - console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -375,26 +363,13 @@ createController(sessionId: string, callback: AsyncCallback\ { - session = data; - console.info(`CreateAVSession : SUCCESS : sessionId = ${session.sessionId}`); -}).catch((err) => { - console.info(`CreateAVSession BusinessError: code: ${err.code}, message: ${err.message}`); -}); - -let controller; -avSession.createController(session.sessionId, function (err, avcontroller) { +let currentAVcontroller; +avSession.createController(currentAVSession.sessionId, function (err, avcontroller) { if (err) { - console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); } else { - controller = avcontroller; - console.info(`CreateController : SUCCESS : ${controller.sessionId}`); + currentAVcontroller = avcontroller; + console.info(`CreateController : SUCCESS : ${currentAVcontroller.sessionId}`); } }); ``` @@ -415,10 +390,10 @@ castAudio(session: SessionToken | 'all', audioDevices: Array | 是 | 媒体设备列表。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | -------------- |------|------| +| session | [SessionToken](#sessiontoken) | 'all' | 是 | 会话令牌。SessionToken表示单个token;字符串`'all'`指所有token。 | +| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\> | 是 | 媒体设备列表。 | **返回值:** @@ -447,13 +422,13 @@ await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then( audioDevices = data; console.info(`Promise returned to indicate that the device list is obtained.`); }).catch((err) => { - console.info(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); }); avSession.castAudio('all', audioDevices).then(() => { console.info(`CreateController : SUCCESS`); }).catch((err) => { - console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -476,8 +451,8 @@ castAudio(session: SessionToken | 'all', audioDevices: Array | 是 | 媒体设备列表。 | -| callback | AsyncCallback\ | 是 | 回调函数。当投播成功,err为undefined,否则返回错误对象。 | +| audioDevices | Array\<[audio.AudioDeviceDescriptor](js-apis-audio.md#audiodevicedescriptor)\> | 是 | 媒体设备列表。 | +| callback | AsyncCallback\ | 是 | 回调函数。当投播成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -500,18 +475,34 @@ await audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then( audioDevices = data; console.info(`Promise returned to indicate that the device list is obtained.`); }).catch((err) => { - console.info(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetDevices BusinessError: code: ${err.code}, message: ${err.message}`); }); avSession.castAudio('all', audioDevices, function (err) { if (err) { - console.info(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`CastAudio BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`CastAudio : SUCCESS `); } }); ``` +## SessionToken + +会话令牌的信息。 + +**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 + +**系统能力:** SystemCapability.Multimedia.AVSession.Manager + +**系统接口:** 该接口为系统接口。 + +| 名称 | 类型 | 必填 | 说明 | +| :-------- | :----- | :--- | :----------- | +| sessionId | string | 是 | 会话ID | +| pid | number | 否 | 会话的进程ID | +| uid | number | 否 | 用户ID | + ## avSession.on('sessionCreate') on(type: 'sessionCreate', callback: (session: AVSessionDescriptor) => void): void @@ -781,9 +772,9 @@ avSession.off('sessionServiceDie'); ## avSession.sendSystemAVKeyEvent -sendSystemAVKeyEvent(event: KeyEvent): Promise\ +sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\): void -发送按键事件给置顶会话。结果通过Promise异步回调方式返回。 +发送按键事件给置顶会话。结果通过callback异步回调方式返回。 **需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 @@ -793,15 +784,10 @@ sendSystemAVKeyEvent(event: KeyEvent): Promise\ **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------------- | ---- | ---------- | -| event | [KeyEvent](js-apis-keyevent.md) | 是 | 按键事件。 | - -**返回值:** - -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当事件发送成功,无返回结果,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- | +| event | [KeyEvent](js-apis-keyevent.md) | 是 | 按键事件。 | +| callback | AsyncCallback\ | 是 | 回调函数。当事件发送成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -814,23 +800,23 @@ sendSystemAVKeyEvent(event: KeyEvent): Promise\ **示例:** ```js - let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let event = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false}; -avSession.sendSystemAVKeyEvent(event).then(() => { - console.info(`SendSystemAVKeyEvent Successfully`); -}).catch((err) => { - console.info(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); +avSession.sendSystemAVKeyEvent(event, function (err) { + if (err) { + console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SendSystemAVKeyEvent : SUCCESS `); + } }); - ``` ## avSession.sendSystemAVKeyEvent -sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\): void +sendSystemAVKeyEvent(event: KeyEvent): Promise\ -发送按键事件给置顶会话。结果通过callback异步回调方式返回。 +发送按键事件给置顶会话。结果通过Promise异步回调方式返回。 **需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 @@ -840,10 +826,15 @@ sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\): void **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------- | -| event | [KeyEvent](js-apis-keyevent.md) | 是 | 按键事件。 | -| callback | AsyncCallback\ | 是 | 回调函数。当事件发送成功,err为undefined,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------------------------------- | ---- | ---------- | +| event | [KeyEvent](js-apis-keyevent.md) | 是 | 按键事件。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当事件发送成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -856,23 +847,22 @@ sendSystemAVKeyEvent(event: KeyEvent, callback: AsyncCallback\): void **示例:** ```js + let keyItem = {code:0x49, pressedTime:2, deviceId:0}; let event = {id:1, deviceId:0, actionTime:1, screenId:1, windowId:1, action:2, key:keyItem, unicodeChar:0, keys:[keyItem], ctrlKey:false, altKey:false, shiftKey:false, logoKey:false, fnKey:false, capsLock:false, numLock:false, scrollLock:false}; -avSession.sendSystemAVKeyEvent(event, function (err) { - if (err) { - console.info(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SendSystemAVKeyEvent : SUCCESS `); - } +avSession.sendSystemAVKeyEvent(event).then(() => { + console.info(`SendSystemAVKeyEvent Successfully`); +}).catch((err) => { + console.error(`SendSystemAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` ## avSession.sendSystemControlCommand -sendSystemControlCommand(command: AVControlCommand): Promise\ +sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\): void -发送控制命令给置顶会话。结果通过Promise异步回调方式返回。 +发送控制命令给置顶会话。结果通过callback异步回调方式返回。 **需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 @@ -882,15 +872,10 @@ sendSystemControlCommand(command: AVControlCommand): Promise\ **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ----------------------------------- | -| command | [AVControlCommand](#avcontrolcommand10) | 是 | AVSession的相关命令和命令相关参数。 | - -**返回值:** - -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| command | [AVControlCommand](#avcontrolcommand10) | 是 | AVSession的相关命令和命令相关参数。 | +| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -920,18 +905,20 @@ let avcommand = {command:cmd}; // let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let cmd : avSession.AVControlCommandType = 'toggleFavorite'; // let avcommand = {command:cmd, parameter:"false"}; -avSession.sendSystemControlCommand(avcommand).then(() => { - console.info(`SendSystemControlCommand successfully`); -}).catch((err) => { - console.info(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); +avSession.sendSystemControlCommand(avcommand, function (err) { + if (err) { + console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`sendSystemControlCommand successfully`); + } }); ``` ## avSession.sendSystemControlCommand -sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\): void +sendSystemControlCommand(command: AVControlCommand): Promise\ -发送控制命令给置顶会话。结果通过callback异步回调方式返回。 +发送控制命令给置顶会话。结果通过Promise异步回调方式返回。 **需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 @@ -941,10 +928,15 @@ sendSystemControlCommand(command: AVControlCommand, callback: AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ----------------------------------- | +| command | [AVControlCommand](#avcontrolcommand10) | 是 | AVSession的相关命令和命令相关参数。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -974,15 +966,27 @@ let avcommand = {command:cmd}; // let avcommand = {command:cmd, parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; // let cmd : avSession.AVControlCommandType = 'toggleFavorite'; // let avcommand = {command:cmd, parameter:"false"}; -avSession.sendSystemControlCommand(avcommand, function (err) { - if (err) { - console.info(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`sendSystemControlCommand successfully`); - } +avSession.sendSystemControlCommand(avcommand).then(() => { + console.info(`SendSystemControlCommand successfully`); +}).catch((err) => { + console.error(`SendSystemControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` +## ProtocolType10+ + +远端设备支持的协议类型。 + +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast + +**系统接口:** 该接口为系统接口。 + +| 名称 | 值 | 说明 | +| --------------------------- | ---- | ----------- | +| TYPE_LOCAL | 0 | 本地设备 | +| TYPE_CAST_PLUS_MIRROR | 1 | Cast+的镜像模式 | +| TYPE_CAST_PLUS_STREAM | 2 | Cast+的Stream模式 | + ## avSession.startCastDeviceDiscovery10+ startCastDeviceDiscovery(callback: AsyncCallback\): void @@ -1005,7 +1009,7 @@ startCastDeviceDiscovery(callback: AsyncCallback\): void ```js avSession.startCastDeviceDiscovery(function (err) { if (err) { - console.info(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`startCastDeviceDiscovery successfully`); } @@ -1036,7 +1040,7 @@ startCastDeviceDiscovery(filter: number, callback: AsyncCallback\): void let filter = 2; avSession.startCastDeviceDiscovery(filter, function (err) { if (err) { - console.info(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`startCastDeviceDiscovery successfully`); } @@ -1071,76 +1075,70 @@ let filter = 2; avSession.startCastDeviceDiscovery(filter).then(() => { console.info(`startCastDeviceDiscovery successfully`); }).catch((err) => { - console.info(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -## avSession.on('deviceAvailable')10+ +## avSession.stopCastDeviceDiscovery10+ -on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void +stopCastDeviceDiscovery(callback: AsyncCallback\): void -设备发现回调监听。 +结束设备搜索发现。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**系统接口:** 该接口为系统接口 +**系统接口:** 该接口为系统接口。 **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'deviceAvailable'`,有设备更新时触发回调。 | -| callback | (device: OutputDeviceInfo) => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。 | - -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | **示例:** ```js -avSession.on('deviceAvailable', (device) => { - console.info(`on deviceAvailable : ${device} `); +avSession.stopCastDeviceDiscovery(function (err) { + if (err) { + console.error(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`stopCastDeviceDiscovery successfully`); + } }); ``` -## avSession.off('deviceAvailable')10+ +## avSession.stopCastDeviceDiscovery10+ -off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): void +stopCastDeviceDiscovery(): Promise\ -取消设备发现回调的监听。 +结束设备搜索发现。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**系统接口:** 该接口为系统接口 - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ---------------------- | ---- | ------------------------------------------------------- | -| type | string | 是 | 事件回调类型,支持事件`'deviceAvailable'`:设备发现回调。| +**系统接口:** 该接口为系统接口。 -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +**返回值:** -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当停止搜索成功,无返回结果,否则返回错误对象。 | **示例:** ```js -avSession.off('deviceAvailable'); +avSession.stopCastDeviceDiscovery().then(() => { + console.info(`startCastDeviceDiscovery successfully`); +}).catch((err) => { + console.error(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -## avSession.stopCastDeviceDiscovery10+ +## avSession.setDiscoverable10+ -stopCastDeviceDiscovery(callback: AsyncCallback\): void +setDiscoverable(enable: boolean, callback: AsyncCallback\): void -结束设备搜索发现。结果通过callback异步回调方式返回。 +设置设备是否可被发现,用于投播接收端。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast @@ -1150,31 +1148,38 @@ stopCastDeviceDiscovery(callback: AsyncCallback\): void | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------- | ---- | ------------------------------------- | +| enable | boolean | 是 | 是否允许本设备被发现. true: 允许被发现, false:不允许被发现 | | callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | **示例:** ```js -avSession.stopCastDeviceDiscovery(function (err) { +avSession.setDiscoverable(true, function (err) { if (err) { - console.info(`stopCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`stopCastDeviceDiscovery successfully`); + console.info(`setDiscoverable successfully`); } }); ``` -## avSession.stopCastDeviceDiscovery10+ +## avSession.setDiscoverable10+ -stopCastDeviceDiscovery(): Promise\ +setDiscoverable(enable: boolean): Promise\ -结束设备搜索发现。结果通过Promise异步回调方式返回。 +设置设备是否可被发现,用于投播接收端。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast **系统接口:** 该接口为系统接口。 +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| enable | boolean | 是 | 是否允许本设备被发现. true: 允许被发现, false:不允许被发现 | + **返回值:** | 类型 | 说明 | @@ -1184,32 +1189,29 @@ stopCastDeviceDiscovery(): Promise\ **示例:** ```js -avSession.stopCastDeviceDiscovery().then(() => { - console.info(`startCastDeviceDiscovery successfully`); +avSession.setDiscoverable(true).then(() => { + console.info(`setDiscoverable successfully`); }).catch((err) => { - console.info(`startCastDeviceDiscovery BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -## avSession.startCasting10+ - -startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCallback\): void +## avSession.on('deviceAvailable')10+ -启动投播。结果通过callback异步回调方式返回。 +on(type: 'deviceAvailable', callback: (device: OutputDeviceInfo) => void): void -**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 +设备发现回调监听。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**系统接口:** 该接口为系统接口。 +**系统接口:** 该接口为系统接口 **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------- | ---- | ------------------------------------- | -| session | [SessionToken](#sessiontoken) | 是 | 会话令牌。SessionToken表示单个token。 | -| device | [OutputDeviceInfo](#outputdeviceinfo10) | 是 | 设备相关信息 | -| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'deviceAvailable'`,有设备更新时触发回调。 | +| callback | (device: OutputDeviceInfo) => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -1217,7 +1219,6 @@ startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCal | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600108 | Device connecting failed. | **示例:** @@ -1227,74 +1228,129 @@ avSession.on('deviceAvailable', (device) => { castDevice = device; console.info(`on deviceAvailable : ${device} `); }); -let myToken = { - sessionId: avSession.sessionId; -} -avSession.startCasting(myToken, castDevice, function (err) { +``` + +## avSession.off('deviceAvailable')10+ + +off(type: 'deviceAvailable', callback?: (device: OutputDeviceInfo) => void): void + +取消设备发现回调的监听。 + +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast + +**系统接口:** 该接口为系统接口 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ---------------------- | ---- | ------------------------------------------------------- | +| type | string | 是 | 事件回调类型,支持事件`'deviceAvailable'`:设备发现回调。| + +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | + +**示例:** + +```js +avSession.off('deviceAvailable'); +``` + +## avSession.getAVCastController10+ + +getAVCastController(sessionId: string, callback: AsyncCallback\): void + +设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。 + +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast + +**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES + +**系统接口:** 该接口为系统接口 + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| sessionId | string | 是 |用于指定要获取的投播控制器的sessionId | +| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | 是 | 回调函数,返回投播控制器实例。 | + +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600101 | Session service exception | +| 6600102 | session does not exist | + +**示例:** + +```js +let aVCastController; +avSession.getAVCastController(sessionId ,function (err, avcontroller) { if (err) { - console.info(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`startCasting successfully`); + aVCastController = avcontroller; + console.info('getAVCastController : SUCCESS '); } }); ``` -## avSession.startCasting10+ - -startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\ +## avSession.getAVCastController10+ -启动投播。结果通过Promise异步回调方式返回。 +getAVCastController(sessionId: string): Promise\; -**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 +设备建立连接后,获取投播控制器。结果通过Promise方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**系统接口:** 该接口为系统接口。 +**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES + +**系统接口:** 该接口为系统接口 **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------- | ---- | ------------------------------------- | -| session | [SessionToken](#sessiontoken) | 是 | 会话令牌。SessionToken表示单个token。 | -| device | [OutputDeviceInfo](#outputdeviceinfo10) | 是 | 设备相关信息 | +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ------------------------- | ---- | ------------------------------------------------------------ | +| sessionId | string | 是 |用于指定要获取的投播控制器的sessionId | **返回值:** -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当停止搜索成功,无返回结果,否则返回错误对象。 | +| 类型 | 说明 | +| --------- | ------------------------------------------------------------ | +| Promise<[AVCastController](#avcastcontroller10)\> | Promise对象。返回投播控制器实例。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600108 | Device connecting failed. | +| 6600101 | server exception | +| 6600102 | The session does not exist | **示例:** ```js -let castDevice; -avSession.on('deviceAvailable', (device) => { - castDevice = device; - console.info(`on deviceAvailable : ${device} `); -}); -let myToken = { - sessionId: avSession.sessionId; -} -avSession.startCasting(myToken, castDevice).then(() => { - console.info(`startCasting successfully`); +let aVCastController; +avSession.getAVCastController(sessionId).then((avcontroller) => { + aVCastController = avcontroller; + console.info('getAVCastController : SUCCESS'); }).catch((err) => { - console.info(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -## avSession.stopCasting10+ +## avSession.startCasting10+ -stopCasting(session: SessionToken, callback: AsyncCallback\): void +startCasting(session: SessionToken, device: OutputDeviceInfo, callback: AsyncCallback\): void -结束投播。结果通过callback异步回调方式返回。 +启动投播。结果通过callback异步回调方式返回。 + +**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast @@ -1304,7 +1360,8 @@ stopCasting(session: SessionToken, callback: AsyncCallback\): void | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------- | ---- | ------------------------------------- | -| session | [SessionToken](#sessiontoken) | 是 | 会话令牌。SessionToken表示单个token。 | +| session | [SessionToken](#sessiontoken) | 是 | 会话令牌。SessionToken表示单个token。 | +| device | [OutputDeviceInfo](#outputdeviceinfo10) | 是 | 设备相关信息 | | callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | **错误码:** @@ -1312,28 +1369,31 @@ stopCasting(session: SessionToken, callback: AsyncCallback\): void | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600109 | The remote connection is not established. | +| 6600101 | Session service exception. | +| 6600108 | Device connecting failed. | **示例:** ```js let myToken = { - sessionId: avSession.sessionId; + sessionId: currentAVSession.sessionId; } -avSession.stopCasting(myToken, castDevice, function (err) { +avSession.startCasting(myToken, castDevice, function (err) { if (err) { - console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`stopCasting successfully`); + console.info(`startCasting successfully`); } }); ``` -## avSession.stopCasting10+ +## avSession.startCasting10+ -stopCasting(session: SessionToken): Promise\ +startCasting(session: SessionToken, device: OutputDeviceInfo): Promise\ -结束投播。结果通过Promise异步回调方式返回。 +启动投播。结果通过Promise异步回调方式返回。 + +**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast @@ -1344,6 +1404,7 @@ stopCasting(session: SessionToken): Promise\ | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------- | ---- | ------------------------------------- | | session | [SessionToken](#sessiontoken) | 是 | 会话令牌。SessionToken表示单个token。 | +| device | [OutputDeviceInfo](#outputdeviceinfo10) | 是 | 设备相关信息 | **返回值:** @@ -1352,31 +1413,31 @@ stopCasting(session: SessionToken): Promise\ | Promise\ | Promise对象。当停止搜索成功,无返回结果,否则返回错误对象。 | **错误码:** -错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600109 | The remote connection is not established. | +| 6600101 | Session service exception. | +| 6600108 | Device connecting failed. | **示例:** ```js let myToken = { - sessionId: avSession.sessionId; + sessionId: currentAVSession.sessionId; } -avSession.stopCasting(myToken).then(() => { - console.info(`stopCasting successfully`); +avSession.startCasting(myToken, castDevice).then(() => { + console.info(`startCasting successfully`); }).catch((err) => { - console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`startCasting BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` +## avSession.stopCasting10+ -## avSession.setDiscoverable10+ - -setDiscoverable(enable: boolean, callback: AsyncCallback\): void +stopCasting(session: SessionToken, callback: AsyncCallback\): void -设置设备是否可被发现,用于投播接收端。结果通过callback异步回调方式返回。 +结束投播。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast @@ -1386,27 +1447,36 @@ setDiscoverable(enable: boolean, callback: AsyncCallback\): void | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------- | ---- | ------------------------------------- | -| enable | boolean | 是 | 是否允许本设备被发现. true: 允许被发现, false:不允许被发现 | +| session | [SessionToken](#sessiontoken) | 是 | 会话令牌。SessionToken表示单个token。 | | callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600109 | The remote connection is not established. | **示例:** ```js -avSession.setDiscoverable(true, function (err) { +let myToken = { + sessionId: currentAVSession.sessionId; +} +avSession.stopCasting(myToken, castDevice, function (err) { if (err) { - console.info(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`setDiscoverable successfully`); + console.info(`stopCasting successfully`); } }); ``` -## avSession.setDiscoverable10+ +## avSession.stopCasting10+ -setDiscoverable(enable: boolean): Promise\ +stopCasting(session: SessionToken): Promise\ -设置设备是否可被发现,用于投播接收端。结果通过Promise异步回调方式返回。 +结束投播。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast @@ -1416,7 +1486,7 @@ setDiscoverable(enable: boolean): Promise\ | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------------------- | ---- | ------------------------------------- | -| enable | boolean | 是 | 是否允许本设备被发现. true: 允许被发现, false:不允许被发现 | +| session | [SessionToken](#sessiontoken) | 是 | 会话令牌。SessionToken表示单个token。 | **返回值:** @@ -1424,16 +1494,36 @@ setDiscoverable(enable: boolean): Promise\ | -------------- | ----------------------------- | | Promise\ | Promise对象。当停止搜索成功,无返回结果,否则返回错误对象。 | +**错误码:** +错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600109 | The remote connection is not established. | + **示例:** ```js -avSession.setDiscoverable(true).then(() => { - console.info(`setDiscoverable successfully`); +let myToken = { + sessionId: currentAVSession.sessionId; +} +avSession.stopCasting(myToken).then(() => { + console.info(`stopCasting successfully`); }).catch((err) => { - console.info(`setDiscoverable BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` +## AVSessionType10+ +当前会话支持的会话类型。 + +**系统能力:** SystemCapability.Multimedia.AVSession.Core + +| 名称 | 类型 | 说明 | +| ----- | ------ | ---- | +| audio | string | 音频 | +| video | string | 视频 | + ## AVSession10+ 调用[avSession.createAVSession](#avsessioncreateavsession10)后,返回会话的实例,可以获得会话ID,完成设置元数据,播放状态信息等操作。 @@ -1450,7 +1540,8 @@ avSession.setDiscoverable(true).then(() => { **示例:** ```js -let sessionId = session.sessionId; +let sessionId = currentAVSession.sessionId; +let sessionType = currentAVSession.sessionType; ``` ### setAVMetadata10+ @@ -1500,10 +1591,10 @@ let metadata = { previousAssetId: "121277", nextAssetId: "121279", }; -session.setAVMetadata(metadata).then(() => { +currentAVSession.setAVMetadata(metadata).then(() => { console.info(`SetAVMetadata successfully`); }).catch((err) => { - console.info(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -1549,9 +1640,9 @@ let metadata = { previousAssetId: "121277", nextAssetId: "121279", }; -session.setAVMetadata(metadata, function (err) { +currentAVSession.setAVMetadata(metadata, function (err) { if (err) { - console.info(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`SetAVMetadata successfully`); } @@ -1597,7 +1688,7 @@ let playbackState = { loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, isFavorite:true, }; -session.setAVPlaybackState(playbackState).then(() => { +currentAVSession.setAVPlaybackState(playbackState).then(() => { console.info(`SetAVPlaybackState successfully`); }).catch((err) => { console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); @@ -1638,7 +1729,7 @@ let PlaybackState = { loopMode:avSession.LoopMode.LOOP_MODE_SINGLE, isFavorite:true, }; -session.setAVPlaybackState(PlaybackState, function (err) { +currentAVSession.setAVPlaybackState(PlaybackState, function (err) { if (err) { console.info(`SetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); } else { @@ -1647,25 +1738,25 @@ session.setAVPlaybackState(PlaybackState, function (err) { }); ``` -### setAVQueueItems10+ +### setLaunchAbility10+ -setAVQueueItems(items: Array\): Promise\ +setLaunchAbility(ability: WantAgent): Promise\ -设置媒体播放列表。结果通过Promise异步回调方式返回。 +设置一个WantAgent用于拉起会话的Ability。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------------------ | ---- | ---------------------------------- | -| items | Array<[AVQueueItem](#avqueueitem10)\> | 是 | 播放列表单项的队列,用以表示播放列表。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| ability | [WantAgent](js-apis-app-ability-wantAgent.md) | 是 | 应用的相关属性信息,如bundleName,abilityName,deviceId等。 | **返回值:** | 类型 | 说明 | | -------------- | ----------------------------- | -| Promise\ | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 | +| Promise\ | Promise对象。当Ability设置成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -1678,221 +1769,7 @@ setAVQueueItems(items: Array\): Promise\ **示例:** ```js -import image from '@ohos.multimedia.image'; -import resourceManager from '@ohos.resourceManager'; - -let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI'); -let imageSource : imageImageSource = image.createImageSource(value.buffer); -let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); -let queueItemDescription_1 = { - mediaId: '001', - title: 'music_name', - subtitle: 'music_sub_name', - description: 'music_description', - icon : imagePixel, - iconUri: 'http://www.icon.uri.com', - extras: {'extras':'any'} -}; -let queueItem_1 = { - itemId: 1, - description: queueItemDescription_1 -}; -let queueItemDescription_2 = { - mediaId: '002', - title: 'music_name', - subtitle: 'music_sub_name', - description: 'music_description', - icon: imagePixel, - iconUri: 'http://www.xxx.com', - extras: {'extras':'any'} -}; -let queueItem_2 = { - itemId: 2, - description: queueItemDescription_2 -}; -let queueItemsArray = [queueItem_1, queueItem_2]; -session.setAVQueueItems(queueItemsArray).then(() => { - console.info(`SetAVQueueItems successfully`); -}).catch((err) => { - console.info(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); -}); -``` - -### setAVQueueItems10+ - -setAVQueueItems(items: Array\, callback: AsyncCallback\): void - -设置媒体播放列表。结果通过callback异步回调方式返回。 - -**系统能力:** SystemCapability.Multimedia.AVSession.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- | -| items | Array<[AVQueueItem](#avqueueitem10)\> | 是 | 播放列表单项的队列,用以表示播放列表。 | -| callback | AsyncCallback\ | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | - -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 - -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | - -**示例:** - -```js -import image from '@ohos.multimedia.image'; -import resourceManager from '@ohos.resourceManager'; - -let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI'); -let imageSource : imageImageSource = image.createImageSource(value.buffer); -let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); -let queueItemDescription_1 = { - mediaId: '001', - title: 'music_name', - subtitle: 'music_sub_name', - description: 'music_description', - icon: imagePixel, - iconUri: 'http://www.icon.uri.com', - extras: {'extras':'any'} -}; -let queueItem_1 = { - itemId: 1, - description: queueItemDescription_1 -}; -let queueItemDescription_2 = { - mediaId: '002', - title: 'music_name', - subtitle: 'music_sub_name', - description: 'music_description', - icon: imagePixel, - iconUri: 'http://www.icon.uri.com', - extras: {'extras':'any'} -}; -let queueItem_2 = { - itemId: 2, - description: queueItemDescription_2 -}; -let queueItemsArray = [queueItem_1, queueItem_2]; -session.setAVQueueItems(queueItemsArray, function (err) { - if (err) { - console.info(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SetAVQueueItems successfully`); - } -}); -``` - -### setAVQueueTitle10+ - -setAVQueueTitle(title: string): Promise\ - -设置媒体播放列表名称。结果通过Promise异步回调方式返回。 - -**系统能力:** SystemCapability.Multimedia.AVSession.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | -------------- | -| title | string | 是 | 播放列表的名称。 | - -**返回值:** - -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 | - -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 - -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | - -**示例:** - -```js -let queueTitle = 'QUEUE_TITLE'; -session.setAVQueueTitle(queueTitle).then(() => { - console.info(`SetAVQueueTitle successfully`); -}).catch((err) => { - console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); -}); -``` - -### setAVQueueTitle10+ - -setAVQueueTitle(title: string, callback: AsyncCallback\): void - -设置媒体播放列表名称。结果通过callback异步回调方式返回。 - -**系统能力:** SystemCapability.Multimedia.AVSession.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | --------------------- | ---- | ----------------------------------------------------------- | -| title | string | 是 | 播放列表名称字段。 | -| callback | AsyncCallback\ | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | - -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 - -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | - -**示例:** - -```js -let queueTitle = 'QUEUE_TITLE'; -session.setAVQueueTitle(queueTitle, function (err) { - if (err) { - console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SetAVQueueTitle successfully`); - } -}); -``` - -### setLaunchAbility10+ - -setLaunchAbility(ability: WantAgent): Promise\ - -设置一个WantAgent用于拉起会话的Ability。结果通过Promise异步回调方式返回。 - -**系统能力:** SystemCapability.Multimedia.AVSession.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | -| ability | [WantAgent](js-apis-app-ability-wantAgent.md) | 是 | 应用的相关属性信息,如bundleName,abilityName,deviceId等。 | - -**返回值:** - -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当Ability设置成功,无返回结果,否则返回错误对象。 | - -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 - -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | - -**示例:** - -```js -import wantAgent from '@ohos.app.ability.wantAgent'; +import wantAgent from '@ohos.app.ability.wantAgent'; //WantAgentInfo对象 let wantAgentInfo = { @@ -1923,10 +1800,10 @@ let wantAgentInfo = { } wantAgent.getWantAgent(wantAgentInfo).then((agent) => { - session.setLaunchAbility(agent).then(() => { + currentAVSession.setLaunchAbility(agent).then(() => { console.info(`SetLaunchAbility successfully`); }).catch((err) => { - console.info(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); }); }); ``` @@ -1988,9 +1865,9 @@ let wantAgentInfo = { } wantAgent.getWantAgent(wantAgentInfo).then((agent) => { - session.setLaunchAbility(agent, function (err) { + currentAVSession.setLaunchAbility(agent, function (err) { if (err) { - console.info(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`SetLaunchAbility successfully`); } @@ -2037,7 +1914,7 @@ let eventName = "dynamic_lyric"; let args = { lyric : "This is lyric" } -await session.dispatchSessionEvent(eventName, args).catch((err) => { +await currentAVSession.dispatchSessionEvent(eventName, args).catch((err) => { console.info(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); }) ``` @@ -2076,35 +1953,32 @@ let eventName = "dynamic_lyric"; let args = { lyric : "This is lyric" } -await session.dispatchSessionEvent(eventName, args, (err) => { +await currentAVSession.dispatchSessionEvent(eventName, args, (err) => { if(err) { - console.info(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`dispatchSessionEvent BusinessError: code: ${err.code}, message: ${err.message}`); } }) ``` -### setExtras10+ +### setAVQueueItems10+ -setExtras(extras: {[key: string]: Object}): Promise\ +setAVQueueItems(items: Array\): Promise\ -媒体提供方设置键值对形式的自定义媒体数据包, 结果通过Promise异步回调方式返回。 +设置媒体播放列表。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | -| extras | {[key: string]: Object} | 是 | 需要传递的自定义媒体数据包键值对 | - -> **说明:** -> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md)。 +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------------------------------------ | ---- | ---------------------------------- | +| items | Array<[AVQueueItem](#avqueueitem10)\> | 是 | 播放列表单项的队列,用以表示播放列表。 | **返回值:** | 类型 | 说明 | | -------------- | ----------------------------- | -| Promise\ | Promise对象。当自定义媒体数据包设置成功,无返回结果,否则返回错误对象。 | +| Promise\ | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -2117,31 +1991,60 @@ setExtras(extras: {[key: string]: Object}): Promise\ **示例:** ```js -let extras = { - extras : "This is custom media packet" -} -await session.setExtras(extras).catch((err) => { - console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); -}) +import image from '@ohos.multimedia.image'; +import resourceManager from '@ohos.resourceManager'; + +let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI'); +let imageSource : imageImageSource = image.createImageSource(value.buffer); +let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); +let queueItemDescription_1 = { + mediaId: '001', + title: 'music_name', + subtitle: 'music_sub_name', + description: 'music_description', + icon : imagePixel, + iconUri: 'http://www.icon.uri.com', + extras: {'extras':'any'} +}; +let queueItem_1 = { + itemId: 1, + description: queueItemDescription_1 +}; +let queueItemDescription_2 = { + mediaId: '002', + title: 'music_name', + subtitle: 'music_sub_name', + description: 'music_description', + icon: imagePixel, + iconUri: 'http://www.xxx.com', + extras: {'extras':'any'} +}; +let queueItem_2 = { + itemId: 2, + description: queueItemDescription_2 +}; +let queueItemsArray = [queueItem_1, queueItem_2]; +currentAVSession.setAVQueueItems(queueItemsArray).then(() => { + console.info(`SetAVQueueItems successfully`); +}).catch((err) => { + console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### setExtras10+ +### setAVQueueItems10+ -setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\): void +setAVQueueItems(items: Array\, callback: AsyncCallback\): void -媒体提供方设置键值对形式的自定义媒体数据包, 结果通过callback异步回调方式返回。 +设置媒体播放列表。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | -| extras | {[key: string]: any} | 是 | 需要传递的自定义媒体数据包键值对 | -| callback | AsyncCallback\ | 是 | 回调函数。当自定义媒体数据包设置成功,err为undefined,否则返回错误对象。 | - -> **说明:** -> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md)。 +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------ | ---- | ----------------------------------------------------------- | +| items | Array<[AVQueueItem](#avqueueitem10)\> | 是 | 播放列表单项的队列,用以表示播放列表。 | +| callback | AsyncCallback\ | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -2154,63 +2057,101 @@ setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\): void **示例:** ```js -let extras = { - extras : "This is custom media packet" -} -await session.setExtras(extras, (err) => { - if(err) { - console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); - } -}) -``` - -### getController10+ - -getController(): Promise\ - -获取本会话对应的控制器。结果通过Promise异步回调方式返回。 - -**系统能力:** SystemCapability.Multimedia.AVSession.Core - -**返回值:** - -| 类型 | 说明 | -| ---------------------------------------------------- | ----------------------------- | -| Promise<[AVSessionController](#avsessioncontroller10)> | Promise对象。返回会话控制器。 | - -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 - -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | - -**示例:** +import image from '@ohos.multimedia.image'; +import resourceManager from '@ohos.resourceManager'; -```js -let controller; -session.getController().then((avcontroller) => { - controller = avcontroller; - console.info(`GetController : SUCCESS : sessionid : ${controller.sessionId}`); -}).catch((err) => { - console.info(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); -}); +let value : Uint8Array = await resourceManager.getRawFileContent('IMAGE_URI'); +let imageSource : imageImageSource = image.createImageSource(value.buffer); +let imagePixel : image.PixelMap = await imageSource.createPixelMap({desiredSize:{width: 150, height: 150}}); +let queueItemDescription_1 = { + mediaId: '001', + title: 'music_name', + subtitle: 'music_sub_name', + description: 'music_description', + icon: imagePixel, + iconUri: 'http://www.icon.uri.com', + extras: {'extras':'any'} +}; +let queueItem_1 = { + itemId: 1, + description: queueItemDescription_1 +}; +let queueItemDescription_2 = { + mediaId: '002', + title: 'music_name', + subtitle: 'music_sub_name', + description: 'music_description', + icon: imagePixel, + iconUri: 'http://www.icon.uri.com', + extras: {'extras':'any'} +}; +let queueItem_2 = { + itemId: 2, + description: queueItemDescription_2 +}; +let queueItemsArray = [queueItem_1, queueItem_2]; +currentAVSession.setAVQueueItems(queueItemsArray, function (err) { + if (err) { + console.error(`SetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SetAVQueueItems successfully`); + } +}); ``` -### getController10+ +### setAVQueueTitle10+ -getController(callback: AsyncCallback\): void +setAVQueueTitle(title: string): Promise\ -获取本会话相应的控制器。结果通过callback异步回调方式返回。 +设置媒体播放列表名称。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------------------------------- | ---- | -------------------------- | -| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | 是 | 回调函数。返回会话控制器。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | -------------- | +| title | string | 是 | 播放列表的名称。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当播放列表设置成功,无返回结果,否则返回错误对象。 | + +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**示例:** + +```js +let queueTitle = 'QUEUE_TITLE'; +currentAVSession.setAVQueueTitle(queueTitle).then(() => { + console.info(`SetAVQueueTitle successfully`); +}).catch((err) => { + console.error(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); +}); +``` + +### setAVQueueTitle10+ + +setAVQueueTitle(title: string, callback: AsyncCallback\): void + +设置媒体播放列表名称。结果通过callback异步回调方式返回。 + +**系统能力:** SystemCapability.Multimedia.AVSession.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------- | ---- | ----------------------------------------------------------- | +| title | string | 是 | 播放列表名称字段。 | +| callback | AsyncCallback\ | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -2223,153 +2164,237 @@ getController(callback: AsyncCallback\): void **示例:** ```js -let controller; -session.getController(function (err, avcontroller) { +let queueTitle = 'QUEUE_TITLE'; +currentAVSession.setAVQueueTitle(queueTitle, function (err) { if (err) { - console.info(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); + console.info(`SetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); } else { - controller = avcontroller; - console.info(`GetController : SUCCESS : sessionid : ${controller.sessionId}`); + console.error(`SetAVQueueTitle successfully`); } }); ``` -### getAVCastController10+ +### setExtras10+ -getAVCastController(callback: AsyncCallback\): void +setExtras(extras: {[key: string]: Object}): Promise\ -设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。 +媒体提供方设置键值对形式的自定义媒体数据包, 结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | 是 | 回调函数,返回投播控制器实例。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| extras | {[key: string]: Object} | 是 | 需要传递的自定义媒体数据包键值对 | + +> **说明:** +> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md)。 + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当自定义媒体数据包设置成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | +| 6600101 | Session service exception. | | 6600102 | The session does not exist. | -| 6600110 | The remote connection is not established. | **示例:** ```js -let controller; -session.getAVCastController().then((avcontroller) => { - controller = avcontroller; - console.info(`getAVCastController : SUCCESS : sessionid : ${controller.sessionId}`); +let extras = { + extras : "This is custom media packet" +} +await currentAVSession.setExtras(extras).catch((err) => { + console.info(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); +}) +``` + +### setExtras10+ + +setExtras(extras: {[key: string]: Object}, callback: AsyncCallback\): void + +媒体提供方设置键值对形式的自定义媒体数据包, 结果通过callback异步回调方式返回。 + +**系统能力:** SystemCapability.Multimedia.AVSession.Core + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------- | --------------------------------------------- | ---- | ----------------------------------------------------------- | +| extras | {[key: string]: any} | 是 | 需要传递的自定义媒体数据包键值对 | +| callback | AsyncCallback\ | 是 | 回调函数。当自定义媒体数据包设置成功,err为undefined,否则返回错误对象。 | + +> **说明:** +> 参数extras支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md)。 + +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**示例:** + +```js +let extras = { + extras : "This is custom media packet" +} +await currentAVSession.setExtras(extras, (err) => { + if(err) { + console.error(`setExtras BusinessError: code: ${err.code}, message: ${err.message}`); + } +}) +``` + +### getController10+ + +getController(): Promise\ + +获取本会话对应的控制器。结果通过Promise异步回调方式返回。 + +**系统能力:** SystemCapability.Multimedia.AVSession.Core + +**返回值:** + +| 类型 | 说明 | +| ---------------------------------------------------- | ----------------------------- | +| Promise<[AVSessionController](#avsessioncontroller10)> | Promise对象。返回会话控制器。 | + +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | + +**示例:** + +```js +let avsessionController; +currentAVSession.getController().then((avcontroller) => { + avsessionController = avcontroller; + console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); }).catch((err) => { - console.info(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getAVCastController10+ +### getController10+ -getAVCastController(): Promise\; +getController(callback: AsyncCallback\): void -设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。 +获取本会话相应的控制器。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**返回值:** +**参数:** -| 类型 | 说明 | -| --------- | ------------------------------------------------------------ | -| Promise<[AVCastController](#avcastcontroller10)\> | Promise对象。返回投播控制器实例。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback<[AVSessionController](#avsessioncontroller10)\> | 是 | 回调函数。返回会话控制器。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | +| 6600101 | Session service exception. | | 6600102 | The session does not exist. | -| 6600110 | The remote connection is not established. | **示例:** ```js -let controller; -session.getAVCastController(function (err, avcontroller) { +let avsessionController; +currentAVSession.getController(function (err, avcontroller) { if (err) { - console.info(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); } else { - controller = avcontroller; - console.info(`getAVCastController : SUCCESS : sessionid : ${controller.sessionId}`); + avsessionController = avcontroller; + console.info(`GetController : SUCCESS : sessionid : ${avsessionController.sessionId}`); } }); ``` -### stopCasting10+ +### getAVCastController10+ -stopCasting(callback: AsyncCallback\): void +getAVCastController(callback: AsyncCallback\): void -停止投播。 +设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------- | ---- | ------------ | -| callback | AsyncCallback\ | 是 | 回调函数。 | +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback<[AVCastController](#avcastcontroller10)\> | 是 | 回调函数,返回投播控制器实例。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600109 | The remote connection is not established. | +| 6600102 | The session does not exist. | +| 6600110 | The remote connection is not established. | **示例:** ```js -session.stopCasting(function (err) { - if (err) { - console.info(`GetController BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - controller = avcontroller; - console.info(`GetController : SUCCESS : sessionid : ${controller.sessionId}`); - } +let aVCastController; +currentAVSession.getAVCastController().then((avcontroller) => { + aVCastController = avcontroller; + console.info(`getAVCastController : SUCCESS : sessionid : ${aVCastController.sessionId}`); +}).catch((err) => { + console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### stopCasting10+ +### getAVCastController10+ -stopCasting(): Promise\; +getAVCastController(): Promise\; -停止投播。 +设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.AVCast **返回值:** -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当停止投播成功,无返回结果,否则返回错误对象。 | +| 类型 | 说明 | +| --------- | ------------------------------------------------------------ | +| Promise<[AVCastController](#avcastcontroller10)\> | Promise对象。返回投播控制器实例。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600109 | The remote connection is not established. | +| 6600102 | The session does not exist. | +| 6600110 | The remote connection is not established. | **示例:** ```js -session.stopCasting().then(() => { - console.info(`stopCasting successfully`); -}).catch((err) => { - console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); +let aVCastController; +currentAVSession.getAVCastController(function (err, avcontroller) { + if (err) { + console.error(`getAVCastController BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + aVCastController = avcontroller; + console.info(`getAVCastController : SUCCESS : sessionid : ${aVCastController.sessionId}`); + } }); ``` - ### getOutputDevice10+ getOutputDevice(): Promise\ @@ -2396,10 +2421,10 @@ getOutputDevice(): Promise\ **示例:** ```js -session.getOutputDevice().then((outputDeviceInfo) => { +currentAVSession.getOutputDevice().then((outputDeviceInfo) => { console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`); }).catch((err) => { - console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -2429,9 +2454,9 @@ getOutputDevice(callback: AsyncCallback\): void **示例:** ```js -session.getOutputDevice(function (err, outputDeviceInfo) { +currentAVSession.getOutputDevice(function (err, outputDeviceInfo) { if (err) { - console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`GetOutputDevice : SUCCESS : isRemote : ${outputDeviceInfo.isRemote}`); } @@ -2463,10 +2488,10 @@ activate(): Promise\ **示例:** ```js -session.activate().then(() => { +currentAVSession.activate().then(() => { console.info(`Activate : SUCCESS `); }).catch((err) => { - console.info(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -2495,9 +2520,9 @@ activate(callback: AsyncCallback\): void **示例:** ```js -session.activate(function (err) { +currentAVSession.activate(function (err) { if (err) { - console.info(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`Activate BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`Activate : SUCCESS `); } @@ -2529,10 +2554,10 @@ deactivate(): Promise\ **示例:** ```js -session.deactivate().then(() => { +currentAVSession.deactivate().then(() => { console.info(`Deactivate : SUCCESS `); }).catch((err) => { - console.info(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -2563,9 +2588,9 @@ deactivate(callback: AsyncCallback\): void **示例:** ```js -session.deactivate(function (err) { +currentAVSession.deactivate(function (err) { if (err) { - console.info(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`Deactivate BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`Deactivate : SUCCESS `); } @@ -2597,10 +2622,10 @@ destroy(): Promise\ **示例:** ```js -session.destroy().then(() => { +currentAVSession.destroy().then(() => { console.info(`Destroy : SUCCESS `); }).catch((err) => { - console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` @@ -2629,9 +2654,9 @@ destroy(callback: AsyncCallback\): void **示例:** ```js -session.destroy(function (err) { +currentAVSession.destroy(function (err) { if (err) { - console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); } else { console.info(`Destroy : SUCCESS `); } @@ -2664,7 +2689,7 @@ on(type: 'play', callback: () => void): void **示例:** ```js -session.on('play', () => { +currentAVSession.on('play', () => { console.info(`on play entry`); }); ``` @@ -2695,7 +2720,7 @@ on(type: 'pause', callback: () => void): void **示例:** ```js -session.on('pause', () => { +currentAVSession.on('pause', () => { console.info(`on pause entry`); }); ``` @@ -2726,7 +2751,7 @@ on(type:'stop', callback: () => void): void **示例:** ```js -session.on('stop', () => { +currentAVSession.on('stop', () => { console.info(`on stop entry`); }); ``` @@ -2757,7 +2782,7 @@ on(type:'playNext', callback: () => void): void **示例:** ```js -session.on('playNext', () => { +currentAVSession.on('playNext', () => { console.info(`on playNext entry`); }); ``` @@ -2788,7 +2813,7 @@ on(type:'playPrevious', callback: () => void): void **示例:** ```js -session.on('playPrevious', () => { +currentAVSession.on('playPrevious', () => { console.info(`on playPrevious entry`); }); ``` @@ -2819,7 +2844,7 @@ on(type: 'fastForward', callback: () => void): void **示例:** ```js -session.on('fastForward', () => { +currentAVSession.on('fastForward', () => { console.info(`on fastForward entry`); }); ``` @@ -2850,7 +2875,7 @@ on(type:'rewind', callback: () => void): void **示例:** ```js -session.on('rewind', () => { +currentAVSession.on('rewind', () => { console.info(`on rewind entry`); }); ``` @@ -2879,9 +2904,9 @@ on(type: 'seek', callback: (time: number) => void): void | 6600102 | The session does not exist. | **示例:** -The session does not exist + ```js -session.on('seek', (time) => { +currentAVSession.on('seek', (time) => { console.info(`on seek entry time : ${time}`); }); ``` @@ -2912,7 +2937,7 @@ on(type: 'setSpeed', callback: (speed: number) => void): void **示例:** ```js -session.on('setSpeed', (speed) => { +currentAVSession.on('setSpeed', (speed) => { console.info(`on setSpeed speed : ${speed}`); }); ``` @@ -2943,7 +2968,7 @@ on(type: 'setLoopMode', callback: (mode: LoopMode) => void): void **示例:** ```js -session.on('setLoopMode', (mode) => { +currentAVSession.on('setLoopMode', (mode) => { console.info(`on setLoopMode mode : ${mode}`); }); ``` @@ -2974,7 +2999,7 @@ on(type: 'toggleFavorite', callback: (assetId: string) => void): void **示例:** ```js -session.on('toggleFavorite', (assetId) => { +currentAVSession.on('toggleFavorite', (assetId) => { console.info(`on toggleFavorite mode : ${assetId}`); }); ``` @@ -3005,7 +3030,7 @@ on(type: 'skipToQueueItem', callback: (itemId: number) => void): void **示例:** ```js -session.on('skipToQueueItem', (itemId) => { +currentAVSession.on('skipToQueueItem', (itemId) => { console.info(`on skipToQueueItem id : ${itemId}`); }); ``` @@ -3036,7 +3061,7 @@ on(type: 'handleKeyEvent', callback: (event: KeyEvent) => void): void **示例:** ```js -session.on('handleKeyEvent', (event) => { +currentAVSession.on('handleKeyEvent', (event) => { console.info(`on handleKeyEvent event : ${event}`); }); ``` @@ -3067,7 +3092,7 @@ on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: Output **示例:** ```js -session.on('outputDeviceChange', (state, device) => { +currentAVSession.on('outputDeviceChange', (state, device) => { console.info(`on outputDeviceChange device : ${device}`); }); ``` @@ -3098,7 +3123,7 @@ on(type: 'commonCommand', callback: (command: string, args: {[key: string]: Obje **示例:** ```js -session.on('commonCommand', (commonCommand, args) => { +currentAVSession.on('commonCommand', (commonCommand, args) => { console.info(`OnCommonCommand, the command is ${commonCommand}, args: ${JSON.stringify(args)}`); }); ``` @@ -3129,7 +3154,7 @@ off(type: 'play', callback?: () => void): void **示例:** ```js -session.off('play'); +currentAVSession.off('play'); ``` ### off('pause')10+ @@ -3158,7 +3183,7 @@ off(type: 'pause', callback?: () => void): void **示例:** ```js -session.off('pause'); +currentAVSession.off('pause'); ``` ### off('stop')10+ @@ -3187,7 +3212,7 @@ off(type: 'stop', callback?: () => void): void **示例:** ```js -session.off('stop'); +currentAVSession.off('stop'); ``` ### off('playNext')10+ @@ -3216,7 +3241,7 @@ off(type: 'playNext', callback?: () => void): void **示例:** ```js -session.off('playNext'); +currentAVSession.off('playNext'); ``` ### off('playPrevious')10+ @@ -3245,7 +3270,7 @@ off(type: 'playPrevious', callback?: () => void): void **示例:** ```js -session.off('playPrevious'); +currentAVSession.off('playPrevious'); ``` ### off('fastForward')10+ @@ -3274,7 +3299,7 @@ off(type: 'fastForward', callback?: () => void): void **示例:** ```js -session.off('fastForward'); +currentAVSession.off('fastForward'); ``` ### off('rewind')10+ @@ -3303,7 +3328,7 @@ off(type: 'rewind', callback?: () => void): void **示例:** ```js -session.off('rewind'); +currentAVSession.off('rewind'); ``` ### off('seek')10+ @@ -3332,7 +3357,7 @@ off(type: 'seek', callback?: (time: number) => void): void **示例:** ```js -session.off('seek'); +currentAVSession.off('seek'); ``` ### off('setSpeed')10+ @@ -3361,7 +3386,7 @@ off(type: 'setSpeed', callback?: (speed: number) => void): void **示例:** ```js -session.off('setSpeed'); +currentAVSession.off('setSpeed'); ``` ### off('setLoopMode')10+ @@ -3390,7 +3415,7 @@ off(type: 'setLoopMode', callback?: (mode: LoopMode) => void): void **示例:** ```js -session.off('setLoopMode'); +currentAVSession.off('setLoopMode'); ``` ### off('toggleFavorite')10+ @@ -3419,7 +3444,7 @@ off(type: 'toggleFavorite', callback?: (assetId: string) => void): void **示例:** ```js -session.off('toggleFavorite'); +currentAVSession.off('toggleFavorite'); ``` ### off('skipToQueueItem')10+ @@ -3448,7 +3473,7 @@ off(type: 'skipToQueueItem', callback?: (itemId: number) => void): void **示例:** ```js -session.off('skipToQueueItem'); +currentAVSession.off('skipToQueueItem'); ``` ### off('handleKeyEvent')10+ @@ -3477,7 +3502,7 @@ off(type: 'handleKeyEvent', callback?: (event: KeyEvent) => void): void **示例:** ```js -session.off('handleKeyEvent'); +currentAVSession.off('handleKeyEvent'); ``` ### off('outputDeviceChange')10+ @@ -3506,7 +3531,7 @@ off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: Outp **示例:** ```js -session.off('outputDeviceChange'); +currentAVSession.off('outputDeviceChange'); ``` @@ -3536,256 +3561,257 @@ off(type: 'commonCommand', callback?: (command: string, args: {[key:string]: Obj **示例:** ```js -session.off('commonCommand'); +currentAVSession.off('commonCommand'); ``` +### stopCasting10+ +stopCasting(callback: AsyncCallback\): void -## AVSessionController10+ +结束投播。结果通过callback异步回调方式返回。 -调用[avSession.createController](#avsessioncreatecontroller)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。 +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -### 属性 +**参数:** -**系统能力:** SystemCapability.Multimedia.AVSession.Core +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | -| 名称 | 类型 | 可读 | 可写 | 说明 | -| :-------- | :----- | :--- | :--- | :-------------------------------------- | -| sessionId | string | 是 | 否 | AVSessionController对象唯一的会话标识。 | +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600109 | The remote connection is not established. | **示例:** + ```js -let sessionId; -await avSession.createController(session.sessionId).then((controller) => { - sessionId = controller.sessionId; -}).catch((err) => { - console.info(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); +currentAVSession.stopCasting(function (err) { + if (err) { + console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`stopCasting successfully`); + } }); ``` -### getAVQueueItems10+ +### stopCasting10+ -getAVQueueItems(): Promise\> +stopCasting(): Promise\ -获取当前会话播放列表相关信息。结果通过Promise异步回调方式返回。 +结束投播。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **返回值:** -| 类型 | 说明 | -| --------------------------------------------- | ----------------------------- | -| Promise\> | Promise对象。返回播放列表队列。 | +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当停止投播索成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | +| 6600109 | The remote connection is not established. | **示例:** + ```js -controller.getAVQueueItems().then((items) => { - console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); +currentAVSession.stopCasting().then(() => { + console.info(`stopCasting successfully`); }).catch((err) => { - console.info(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); + console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getAVQueueItems10+ +## AVCastControlCommandType10+ -getAVQueueItems(callback: AsyncCallback\>): void +投播控制器可传递的命令。 -获取当前播放列表相关信息。结果通过callback异步回调方式返回。 +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**系统能力:** SystemCapability.Multimedia.AVSession.Core +| 名称 | 类型 | 说明 | +| -------------- | ------ | ------------ | +| play | string | 播放 | +| pause | string | 暂停 | +| stop | string | 停止 | +| playNext | string | 下一首 | +| playPrevious | string | 上一首 | +| fastForward | string | 快进 | +| rewind | string | 快退 | +| seek | numbder | 跳转某一节点 | +| setSpeed | number | 设置播放倍速 | +| setLoopMode | string | 设置循环模式 | +| toggleFavorite | string | 是否收藏 | +| setVolume | number | 设置音量 | -**参数:** +## AVCastControlCommand10+ -| 参数名 | 类型 | 必填 | 说明 | -| -------- | --------------------------------------------------- | ---- | ------------------------- | -| callback | AsyncCallback\> | 是 | 回调函数,返回播放列表队列。 | +投播控制器接受的命令的对象描述。 -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------------------------------------------------- | ---- | -------------- | +| command | [AVCastControlCommandType](#avcastcontrolcommandtype10) | 是 | 命令 | +| parameter | [LoopMode](#loopmode10) | string | number | 否 | 命令对应的参数 | -**示例:** -```js -controller.getAVQueueItems(function (err, items) { - if (err) { - console.info(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); - } -}); -``` +## AVCastController10+ -### getAVQueueTitle10+ +在投播建立后,调用[avSession.getAVCastController](#getavcastcontroller10)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。 -getAVQueueTitle(): Promise\ +### setDisplaySurface10+ -获取当前会话播放列表的名称。结果通过Promise异步回调方式返回。 +setDisplaySurface(surfaceId: string): Promise\ -**系统能力:** SystemCapability.Multimedia.AVSession.Core +设置播放的surfaceId,在投播sink端使用。结果通过Promise异步回调方式返回。 + +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast + +**系统接口:** 该接口为系统接口。 **返回值:** -| 类型 | 说明 | -| ---------------- | ----------------------------- | -| Promise | Promise对象。返回播放列表名称。 | +| 类型 | 说明 | +| --------------------------------------------- | --------------------------- | +| Promise\ | Promise对象。返回设置结果。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | +| 6600109 | The remote connection is not established. | **示例:** ```js -controller.getAVQueueTitle().then((title) => { - console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); -}).catch((err) => { - console.info(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); +aVCastController.setDisplaySurface().then(() => { + console.info(`setDisplaySurface : SUCCESS :`); }); ``` -### getAVQueueTitle10+ +### setDisplaySurface10+ -getAVQueueTitle(callback: AsyncCallback\): void +setDisplaySurface(surfaceId: string, callback: AsyncCallback\): void -获取当前播放列表的名称。结果通过callback异步回调方式返回。 +设置播放的surfaceId,在投播sink端使用。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast + +**系统接口:** 该接口为系统接口。 **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------------------- | ---- | ------------------------- | -| callback | AsyncCallback | 是 | 回调函数,返回播放列表名称。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------------------------------- | ---- | ---------------------------- | +| callback | AsyncCallback\ | 是 | 回调函数,返回当前设置结果。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | +| 6600109 | The remote connection is not established. | **示例:** ```js -controller.getAVQueueTitle(function (err, title) { +aVCastController.setDisplaySurface(function (err, value) { if (err) { - console.info(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); + console.info(`setDisplaySurface BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); + console.info(`setDisplaySurface : SUCCESS : state : ${value}`); } }); ``` -### skipToQueueItem10+ +### getAVPlaybackState10+ -skipToQueueItem(itemId: number): Promise\ +getAVPlaybackState(callback: AsyncCallback\): void -设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过Promise异步回调方式返回。 +设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------- | ---- | ------------------------------------------- | -| itemId | number | 是 | 播放列表单项的ID值,用以表示选中的播放列表单项。 | - -**返回值:** - -| 类型 | 说明 | -| -------------- | --------------------------------------------------------------- | -| Promise\ | Promise对象。当播放列表单项ID设置成功,无返回结果,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback<[[AVPlaybackState](#avplaybackstate10))\> | 是 | 回调函数,返回投播控制器实例。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | +| 6600101 | Session service exception | **示例:** ```js -let queueItemId = 0; -controller.skipToQueueItem(queueItemId).then(() => { - console.info(`SkipToQueueItem successfully`); -}).catch((err) => { - console.info(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); +aVCastController.getAVPlaybackState(function (err, state) { + if (err) { + console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`getAVPlaybackState : SUCCESS`); + } }); ``` -### skipToQueueItem10+ +### getAVPlaybackState10+ -skipToQueueItem(itemId: number, callback: AsyncCallback\): void +getAVPlaybackState(): Promise\; -设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过callback异步回调方式返回。 +获取当前的远端播放状态。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | --------------------- | ---- | ----------------------------------------------------------- | -| itemId | number | 是 | 播放列表单项的ID值,用以表示选中的播放列表单项。 | -| callback | AsyncCallback\ | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | +| 类型 | 说明 | +| --------- | ------------------------------------------------------------ | +| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise对象。返回投播控制器实例。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | +| 6600101 | Session service exception | **示例:** ```js -let queueItemId = 0; -controller.skipToQueueItem(queueItemId, function (err) { - if (err) { - console.info(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SkipToQueueItem successfully`); - } +aVCastController.getAVPlaybackState().then((state) => { + console.info(`getAVPlaybackState : SUCCESS :`); +}).catch((err) => { + console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getAVMetadata10+ +### sendControlCommand10+ -getAVMetadata(): Promise\ +sendControlCommand(command: AVCastControlCommand): Promise\ -获取会话元数据。结果通过Promise异步回调方式返回。 +通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core + +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | **返回值:** -| 类型 | 说明 | -| ----------------------------------- | ----------------------------- | -| Promise<[AVMetadata](#avmetadata10)\> | Promise对象,返回会话元数据。 | +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -3793,131 +3819,194 @@ getAVMetadata(): Promise\ | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600109 | The remote connection is not established. | **示例:** + ```js -controller.getAVMetadata().then((metadata) => { - console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); +let avCommand = {command:'play'}; +// let avCommand = {command:'pause'}; +// let avCommand = {command:'stop'}; +// let avCommand = {command:'playNext'}; +// let avCommand = {command:'playPrevious'}; +// let avCommand = {command:'fastForward'}; +// let avCommand = {command:'rewind'}; +// let avCommand = {command:'seek', parameter:10}; +aVCastController.sendControlCommand(avCommand).then(() => { + console.info(`SendControlCommand successfully`); }).catch((err) => { - console.info(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getAVMetadata10+ +### sendControlCommand10+ -getAVMetadata(callback: AsyncCallback\): void +sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\): void -获取会话元数据。结果通过callback异步回调方式返回。 +通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core + +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------------- | ---- | -------------------------- | -| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | 是 | 回调函数,返回会话元数据。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------- | ---- | ------------------------------ | +| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | +| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600109 | The remote connection is not established. | **示例:** + ```js -controller.getAVMetadata(function (err, metadata) { +let avCommand = {command:'play'}; +// let avCommand = {command:'pause'}; +// let avCommand = {command:'stop'}; +// let avCommand = {command:'playNext'}; +// let avCommand = {command:'playPrevious'}; +// let avCommand = {command:'fastForward'}; +// let avCommand = {command:'rewind'}; +// let avCommand = {command:'seek', parameter:10}; +aVCastController.sendControlCommand(avCommand, function (err) { if (err) { - console.info(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); + console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); } else { - console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); + console.info(`SendControlCommand successfully`); } }); ``` -### getOutputDevice10+ +### prepare10+ -getOutputDevice(): Promise\ +prepare(item: AVQueueItem, callback: AsyncCallback\): void -获取播放设备信息。结果通过Promise异步回调方式返回。 +启动播放某个媒体资源。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**返回值:** +**参数:** -| 类型 | 说明 | -| ----------------------------------------------- | --------------------------------- | -| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise对象,返回播放设备信息。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | +| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 **错误码:** - 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 600101 | Session service exception. | -| 600103 | The session controller does not exist. | +| 6600101 | Session service exception. | **示例:** + ```js -controller.getOutputDevice().then((deviceInfo) => { - console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); -}).catch((err) => { - console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); +// 设置播放参数,开始播放 +var playItem = { + itemId: 0, + description: { + mediaId: '12345', + mediaName: 'song1', + mediaType: 'AUDIO', + mediaUri: 'http://resource1_address', + mediaSize: 12345, + startPosition: 0, + duration: 0, + artist: 'mysong', + albumTitle: 'song1_title', + albumCoverUri: "http://resource1_album_address", + lyricUri: "http://resource1_lyric_address", + iconUri: "http://resource1_icon_address", + appName: 'MyMusic' + } +}; +// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 +aVCastController.prepare(playItem, () => { + console.info('prepare done'); }); ``` -### getOutputDevice10+ -getOutputDevice(callback: AsyncCallback\): void +### prepare10+ -获取播放设备信息。结果通过callback异步回调方式返回。 +prepare(item: AVQueueItem): Promise\ -**系统能力:** SystemCapability.Multimedia.AVSession.Core +启动播放某个媒体资源。结果通过Promise异步回调方式返回。 + + +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------------------------- | ---- | ------------------------------ | -| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | 是 | 回调函数,返回播放设备信息。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 600101 | Session service exception. | -| 600103 | The session controller does not exist. | +| 6600101 | Session service exception. | + **示例:** ```js -controller.getOutputDevice(function (err, deviceInfo) { - if (err) { - console.info(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); +// 设置播放参数,开始播放 +var playItem = { + itemId: 0, + description: { + mediaId: '12345', + mediaName: 'song1', + mediaType: 'AUDIO', + mediaUri: 'http://resource1_address', + mediaSize: 12345, + startPosition: 0, + duration: 0, + artist: 'mysong', + albumTitle: 'song1_title', + albumCoverUri: "http://resource1_album_address", + lyricUri: "http://resource1_lyric_address", + iconUri: "http://resource1_icon_address", + appName: 'MyMusic' } +}; +// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 +aVCastController.prepare(playItem, () => { + console.info('prepare done'); }); ``` -### getExtras10+ +### start10+ -getExtras(): Promise\<{[key: string]: Object}> +start(item: AVQueueItem, callback: AsyncCallback\): void -获取媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。 +启动播放某个媒体资源。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**返回值:** +**参数:** -| 类型 | 说明 | -| ----------------------------------- | ----------------------------- | -| Promise<{[key: string]: Object}\> | Promise对象,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | +| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -3925,31 +4014,56 @@ getExtras(): Promise\<{[key: string]: Object}> | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | -| 6600105 | Invalid session command. | -| 6600107 | Too many commands or events. | **示例:** + ```js -let extras = await controller.getExtras().catch((err) => { - console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); +// 设置播放参数,开始播放 +var playItem = { +itemId: 0, +description: { + mediaId: '12345', + mediaName: 'song1', + mediaType: 'AUDIO', + mediaUri: 'http://resource1_address', + mediaSize: 12345, + startPosition: 0, + duration: 0, + artist: 'mysong', + albumTitle: 'song1_title', + albumCoverUri: "http://resource1_album_address", + lyricUri: "http://resource1_lyric_address", + iconUri: "http://resource1_icon_address", + appName: 'MyMusic' +} +}; + +// 启动播放 +aVCastController.start(playItem, () => { + console.info('play done'); }); ``` -### getExtras10+ +### start10+ -getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void +start(item: AVQueueItem): Promise\ -获取媒体提供方设置的自定义媒体数据包,结果通过callback异步回调方式返回。 +启动播放某个媒体资源。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core + +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------------- | ---- | -------------------------- | -| callback | AsyncCallback<{[key: string]: Object}\> | 是 | 回调函数,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -3957,1260 +4071,1244 @@ getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | -| 6600105 | Invalid session command. | -| 6600107 | Too many commands or events. | + **示例:** + ```js -let metadata = { - assetId: "121278", - title: "lose yourself", - artist: "Eminem", - author: "ST", - album: "Slim shady", - writer: "ST", - composer: "ST", - duration: 2222, - mediaImage: "https://www.example.com/example.jpg", - subtitle: "8 Mile", - description: "Rap", - lyric: "https://www.example.com/example.lrc", - previousAssetId: "121277", - nextAssetId: "121279", +// 设置播放参数,开始播放 +var playItem = { +itemId: 0, +description: { + mediaId: '12345', + mediaName: 'song1', + mediaType: 'AUDIO', + mediaUri: 'http://resource1_address', + mediaSize: 12345, + startPosition: 0, + duration: 0, + artist: 'mysong', + albumTitle: 'song1_title', + albumCoverUri: "http://resource1_album_address", + lyricUri: "http://resource1_lyric_address", + iconUri: "http://resource1_icon_address", + appName: 'MyMusic' +} }; -controller.getExtras(function (err, extras) { - if (err) { - console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`getExtras : SUCCESS : assetId : ${metadata.assetId}`); - } +// 启动播放 +aVCastController.start(playItem).then(() => { + console.info(`start successfully`); +}).catch((err) => { + console.info(`start BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### sendAVKeyEvent10+ +### getCurrentItem10+ -sendAVKeyEvent(event: KeyEvent): Promise\ +getCurrentItem(callback: AsyncCallback\): void -发送按键事件到控制器对应的会话。结果通过Promise异步回调方式返回。 +获取当前投播的资源信息。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------------------------------------------------------------ | ---- | ---------- | -| event | [KeyEvent](js-apis-keyevent.md) | 是 | 按键事件。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------- | ---- | ------------------------------------- | +| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 600101 | Session service exception. | -| 600102 | The session does not exist. | -| 600103 | The session controller does not exist. | -| 600105 | Invalid session command. | -| 600106 | The session is not activated. | - -**返回值:** - -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当事件发送成功,无返回结果,否则返回错误对象。 | +| 6600101 | Session service exception. | **示例:** ```js -let keyItem = {code:0x49, pressedTime:2, deviceId:0}; -let event = {action:2, key:keyItem, keys:[keyItem]}; - -controller.sendAVKeyEvent(event).then(() => { - console.info(`SendAVKeyEvent Successfully`); -}).catch((err) => { - console.info(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); +aVCastController.getCurrentItem(function (err, value) { + if (err) { + console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`getCurrentItem successfully`); + } }); ``` -### sendAVKeyEvent10+ +### getCurrentItem10+ -sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\): void +getCurrentItem(): Promise\ -发送按键事件到会话。结果通过callback异步回调方式返回。 +结束投播。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ---------- | -| event | [KeyEvent](js-apis-keyevent.md) | 是 | 按键事件。 | -| callback | AsyncCallback\ | 是 | 回调函数。当事件发送成功,err为undefined,否则返回错误对象。 | +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\<[AVQueueItem](#avqueueitem10)> | Promise对象,返回当前的播放资源,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 600101 | Session service exception. | -| 600102 | The session does not exist. | -| 600103 | The session controller does not exist. | -| 600105 | Invalid session command. | -| 600106 | The session is not activated. | +| 6600101 | Session service exception. | **示例:** ```js -let keyItem = {code:0x49, pressedTime:2, deviceId:0}; -let event = {action:2, key:keyItem, keys:[keyItem]}; - -controller.sendAVKeyEvent(event, function (err) { - if (err) { - console.info(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SendAVKeyEvent Successfully`); - } +aVCastController.getCurrentItem().then((AVQueueItem) => { + console.info(`getCurrentItem successfully`); +}).catch((err) => { + console.error(`getCurrentItem BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getLaunchAbility10+ +### on('playbackStateChange')10+ -getLaunchAbility(): Promise\ +on(type: 'playbackStateChange', filter: Array\ | 'all', callback: (state: AVPlaybackState) => void): void -获取应用在会话中保存的WantAgent对象。结果通过Promise异步回调方式返回。 +设置播放状态变化的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**返回值:** +**参数:** -| 类型 | 说明 | -| ------------------------------------------------------- | ------------------------------------------------------------ | -| Promise<[WantAgent](js-apis-app-ability-wantAgent.md)\> | Promise对象,返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 | +| filter | Array\ | 'all' | 是 | 'all' 表示关注播放状态所有字段变化;Array 表示关注Array中的字段变化。 | +| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 是 | 回调函数,参数state是变化后的播放状态。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | **示例:** ```js -import wantAgent from '@ohos.app.ability.wantAgent'; +aVCastController.on('playbackStateChange', 'all', (playbackState) => { + console.info(`on playbackStateChange state : ${playbackState.state}`); +}); -controller.getLaunchAbility().then((agent) => { - console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); -}).catch((err) => { - console.info(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); +let playbackFilter = ['state', 'speed', 'loopMode']; +aVCastController.on('playbackStateChange', playbackFilter, (playbackState) => { + console.info(`on playbackStateChange state : ${playbackState.state}`); }); ``` -### getLaunchAbility10+ +### off('playbackStateChange')10+ -getLaunchAbility(callback: AsyncCallback\): void +off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void -获取应用在会话中保存的WantAgent对象。结果通过callback异步回调方式返回。 +媒体控制器取消监听播放状态变化的事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| callback | AsyncCallback<[WantAgent](js-apis-app-ability-wantAgent.md)\> | 是 | 回调函数。返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'playbackStateChange'`。 | +| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 否 | 回调函数,参数state是变化后的播放状态。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | **示例:** ```js -import wantAgent from '@ohos.app.ability.wantAgent'; - -controller.getLaunchAbility(function (err, agent) { - if (err) { - console.info(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); - } -}); +aVCastController.off('playbackStateChange'); ``` -### getRealPlaybackPositionSync10+ +### on('mediaItemChange')10+ -getRealPlaybackPositionSync(): number +on(type: 'mediaItemChange', callback: Callback\): void -获取当前播放位置。 +设置投播当前播放媒体内容的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**返回值:** +**参数:** -| 类型 | 说明 | -| ------ | ------------------ | -| number | 时间节点,毫秒数。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'mediaItemChange'`:当播放状态变化时,触发该事件。 | +| callback | (state: [AVQueueItem](#avqueueitem10)) => void | 是 | 回调函数,参数AVQueueItem是d当前正在播放的媒体内容。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | **示例:** ```js -let time = controller.getRealPlaybackPositionSync(); +aVCastController.on('mediaItemChange', (item) => { + console.info(`on mediaItemChange state : ${item.itemId}`); +}); ``` -### isActive10+ +### off('mediaItemChange')10+ -isActive(): Promise\ +off(type: 'mediaItemChange'): void -获取会话是否被激活。结果通过Promise异步回调方式返回。 +取消设置投播当前播放媒体内容的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**返回值:** +**参数:** -| 类型 | 说明 | -| ----------------- | ------------------------------------------------------------ | -| Promise | Promise对象,返回会话是否为激活状态,true表示被激活,false表示禁用。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'mediaItemChange'`。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | **示例:** ```js -controller.isActive().then((isActive) => { - console.info(`IsActive : SUCCESS : isactive : ${isActive}`); -}).catch((err) => { - console.info(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); -}); +aVCastController.off('mediaItemChange'); ``` -### isActive10+ +### on('playNext')10+ -isActive(callback: AsyncCallback\): void +on(type: 'playNext', callback: Callback\): void -判断会话是否被激活。结果通过callback异步回调方式返回。 +设置播放下一首资源的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------- | ---- | ------------------------------------------------------------ | -| callback | AsyncCallback | 是 | 回调函数,返回会话是否为激活状态,true表示被激活,false表示禁用。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'playNext'`:当播放下一首状态变化时,触发该事件。 | +| callback | Callback\ | 是 | 回调函数 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | **示例:** ```js -controller.isActive(function (err, isActive) { - if (err) { - console.info(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`IsActive : SUCCESS : isactive : ${isActive}`); - } +aVCastController.on('playNext', () => { + console.info(`on playNext`); }); ``` -### destroy10+ +### off('playNext')10+ -destroy(): Promise\ +off(type: 'playNext'): void -销毁当前控制器,销毁后当前控制器不可再用。结果通过Promise异步回调方式返回。 +取消设置播放下一首资源的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**返回值:** +**参数:** -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当控制器销毁成功,无返回结果,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'playNext'`。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | **示例:** ```js -controller.destroy().then(() => { - console.info(`Destroy : SUCCESS `); -}).catch((err) => { - console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); -}); +aVCastController.off('playNext'); ``` -### destroy10+ +### on('playPrevious')10+ -destroy(callback: AsyncCallback\): void +on(type: 'playPrevious', callback: Callback\): void -销毁当前控制器,销毁后当前控制器不可再用。结果通过callback异步回调方式返回。 +设置播放上一首资源的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------------------- | ---- | ---------- | -| callback | AsyncCallback\ | 是 | 回调函数。当控制器销毁成功,err为undefined,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'playPrevious'`:当播放下一首状态变化时,触发该事件。 | +| callback | Callback\ | 是 | 回调函数 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | **示例:** ```js -controller.destroy(function (err) { - if (err) { - console.info(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`Destroy : SUCCESS `); - } +aVCastController.on('playPrevious', () => { + console.info(`on playPrevious`); }); ``` -### getValidCommands10+ +### off('playPrevious')10+ -getValidCommands(): Promise\> +off(type: 'playPrevious'): void -获取会话支持的有效命令。结果通过Promise异步回调方式返回。 +取消设置播放下一首资源的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**返回值:** +**参数:** -| 类型 | 说明 | -| ------------------------------------------------------------ | --------------------------------- | -| Promise\> | Promise对象。返回有效命令的集合。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'playPrevious'`。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | **示例:** ```js -controller.getValidCommands.then((validCommands) => { - console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); -}).catch((err) => { - console.info(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); -}); +aVCastController.off('playPrevious'); ``` -### getValidCommands10+ +### on('seekDone')10+ -getValidCommands(callback: AsyncCallback\>): void +on(type: 'seekDone', callback: Callback\): void -获取会话支持的有效命令。结果通过callback异步回调方式返回。 +设置seek结束的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | -| callback | AsyncCallback\\> | 是 | 回调函数,返回有效命令的集合。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'seekDone'`:当seek结束时,触发该事件。 | +| callback | Callback\ | 是 | 回调函数,返回seek后播放的位置 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | **示例:** ```js -controller.getValidCommands(function (err, validCommands) { - if (err) { - console.info(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); - } +aVCastController.on('seekDone', (pos) => { + console.info(`on seekDone pos:${pos} `); }); ``` -### sendControlCommand10+ - -sendControlCommand(command: AVControlCommand): Promise\ +### off('seekDone')10+ -通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。 +off(type: 'seekDone'): void -> **说明:** -> -> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[注册媒体会话相关监听](#onplaypausestopplaynextplaypreviousfastforwardrewind10)。 +取消设置seek结束的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ------------------------------ | -| command | [AVControlCommand](#avcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | - -**返回值:** - -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'seekDone'`。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | -| 6600105 | Invalid session command. | -| 6600106 | The session is not activated. | -| 6600107 | Too many commands or events. | **示例:** ```js -let avCommand = {command:'play'}; -// let avCommand = {command:'pause'}; -// let avCommand = {command:'stop'}; -// let avCommand = {command:'playNext'}; -// let avCommand = {command:'playPrevious'}; -// let avCommand = {command:'fastForward'}; -// let avCommand = {command:'rewind'}; -// let avCommand = {command:'seek', parameter:10}; -// let avCommand = {command:'setSpeed', parameter:2.6}; -// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; -// let avCommand = {command:'toggleFavorite', parameter:"false"}; -controller.sendControlCommand(avCommand).then(() => { - console.info(`SendControlCommand successfully`); -}).catch((err) => { - console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); -}); +aVCastController.off('seekDone'); ``` -### sendControlCommand10+ +### on('videoSizeChange')10+ -sendControlCommand(command: AVControlCommand, callback: AsyncCallback\): void +on(type: 'videoSizeChange', callback: (width:number, height:number) => void): void -通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。 +设置video尺寸更改监听事件。 -> **说明:** -> -> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[注册媒体会话相关监听](#onplaypausestopplaynextplaypreviousfastforwardrewind10)。 +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统接口:** 该接口为系统接口 **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------- | ---- | ------------------------------ | -| command | [AVControlCommand](#avcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | -| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | - -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 - -| 错误码ID | 错误信息 | -| -------- | ------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | -| 6600105 | Invalid session command. | -| 6600106 | The session is not activated. | -| 6600107 | Too many commands or events. | +| 参数名 | 类型 | 必填 | 说明 | +| type | string | 是 | 事件回调类型,支持事件`'videoSizeChange'`:当video尺寸更改时,触发该事件。 | +| callback | (width:number, height:number) => void | 是 | 回调函数,返回video的宽度和高度 | **示例:** ```js -let avCommand = {command:'play'}; -// let avCommand = {command:'pause'}; -// let avCommand = {command:'stop'}; -// let avCommand = {command:'playNext'}; -// let avCommand = {command:'playPrevious'}; -// let avCommand = {command:'fastForward'}; -// let avCommand = {command:'rewind'}; -// let avCommand = {command:'seek', parameter:10}; -// let avCommand = {command:'setSpeed', parameter:2.6}; -// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; -// let avCommand = {command:'toggleFavorite', parameter:"false"}; -controller.sendControlCommand(avCommand, function (err) { - if (err) { - console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SendControlCommand successfully`); - } +aVCastController.on('videoSizeChange', (width, height) => { + console.info(`width :${width} `); + console.info(`height:${height} `); }); ``` -### sendCommonCommand10+ +### off('videoSizeChange')10+ -sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\ +off(type: 'videoSizeChange'): void -通过会话控制器发送自定义控制命令到其对应的会话。结果通过Promise异步回调方式返回。 - -**系统能力:** SystemCapability.Multimedia.AVSession.Core - -**参数:** +取消设置video尺寸更改监听事件。 -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ------------------------------ | -| command | string | 是 | 需要设置的自定义控制命令的名称 | -| args | {[key: string]: any} | 是 | 需要传递的控制命令键值对 | - -> **说明:** -> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md)。 - -**返回值:** +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | +**系统接口:** 该接口为系统接口 -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +**参数:** -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | -| 6600105 | Invalid session command. | -| 6600106 | The session is not activated. | -| 6600107 | Too many commands or events. | +| 参数名 | 类型 | 必填 | 说明 | +| type | string | 是 | 取消对应的监听事件,支持事件`'videoSizeChange'`。 | **示例:** ```js -let commandName = "my_command"; -let args = { - command : "This is my command" -} -await controller.sendCommonCommand(commandName, args).catch((err) => { - console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); -}) +aVCastController.off('videoSizeChange'); ``` -### sendCommonCommand10+ +### on('error')10+ -sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\): void +on(type: 'error', callback: ErrorCallback): void -通过会话控制器发送自定义命令到其对应的会话。结果通过callback异步回调方式返回。 +监听远端播放器的错误事件,该事件仅用于错误提示,不需要用户停止播控动作。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ------------------------------ | -| command | string | 是 | 需要设置的自定义控制命令的名称 | -| args | {[key: string]: any} | 是 | 需要传递的控制命令键值对 | -| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | - -> **说明:** -> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md)。 +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 错误事件回调类型,支持的事件:'error',用户操作和系统都会触发此事件。 | +| callback | function | 是 | 错误事件回调方法:远端播放过程中发生的错误,会提供错误码ID和错误信息。 | **错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -| 错误码ID | 错误信息 | -| -------- | ------------------------------- | -| 6600101 | Session service exception. | -| 6600102 | The session does not exist. | -| 6600103 | The session controller does not exist. | -| 6600105 | Invalid session command. | -| 6600106 | The session is not activated. | -| 6600107 | Too many commands or events. | +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-media.md)。 + +| 错误码ID | 错误信息 | +| -------- | --------------------- | +| 5400101 | No memory. | +| 5400102 | Operation not allowed. | +| 5400103 | I/O error. | +| 5400104 | Time out. | +| 5400105 | Service died. | +| 5400106 | Unsupport format. | **示例:** ```js -let commandName = "my_command"; -let args = { - command : "This is my command" -} -controller.sendCommonCommand(commandName, args, (err) => { - if(err) { - console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); - } +aVCastController.on('error', (error) => { + console.error('error happened,and error message is :' + error.message) + console.error('error happened,and error code is :' + error.code) }) ``` -### on('metadataChange')10+ +### off('error')10+ -on(type: 'metadataChange', filter: Array\ | 'all', callback: (data: AVMetadata) => void) +off(type: 'error'): void -设置元数据变化的监听事件。 +取消监听播放的错误事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'metadataChange'`:当元数据变化时,触发该事件。 | -| filter | Array\ | 'all' | 是 | 'all' 表示关注元数据所有字段变化;Array 表示关注Array中的字段变化。 | -| callback | (data: [AVMetadata](#avmetadata10)) => void | 是 | 回调函数,参数data是变化后的元数据。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ----------------------------------------- | +| type | string | 是 | 错误事件回调类型,取消注册的事件:'error' | **错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -| 错误码ID | 错误信息 | -| -------- | ------------------------------ | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-media.md)。 + +| 错误码ID | 错误信息 | +| -------- | --------------------- | +| 5400101 | No memory. | +| 5400102 | Operation not allowed. | +| 5400103 | I/O error. | +| 5400104 | Time out. | +| 5400105 | Service died. | +| 5400106 | Unsupport format. | **示例:** ```js -controller.on('metadataChange', 'all', (metadata) => { - console.info(`on metadataChange assetId : ${metadata.assetId}`); -}); - -let metaFilter = ['assetId', 'title', 'description']; -controller.on('metadataChange', metaFilter, (metadata) => { - console.info(`on metadataChange assetId : ${metadata.assetId}`); -}); +aVCastController.off('error') ``` -### on('playbackStateChange')10+ +## ConnectionState10+ -on(type: 'playbackStateChange', filter: Array\ | 'all', callback: (state: AVPlaybackState) => void) +播放设备的类别枚举。 -设置播放状态变化的监听事件。 +**系统能力:** SystemCapability.Multimedia.AVSession.Core + +| 名称 | 值 | 说明 | +| --------------------------- | ---- | ----------- | +| STATE_CONNECTING | 0 | 设备连接中 | +| STATE_CONNECTED | 1 | 设备连接成功 | +| STATE_DISCONNECTED | 6 | 设备断开连接 | + +## AVMetadata10+ + +媒体元数据的相关属性。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +| 名称 | 类型 | 必填 | 说明 | +| --------------- |-------------------------| ---- |---------------------------------------------------------------------| +| assetId | string | 是 | 媒体ID。 | +| title | string | 否 | 标题。 | +| artist | string | 否 | 艺术家。 | +| author | string | 否 | 专辑作者。 | +| album | string | 否 | 专辑名称。 | +| writer | string | 否 | 词作者。 | +| composer | string | 否 | 作曲者。 | +| duration | number | 否 | 媒体时长,单位毫秒(ms)。 | +| mediaImage | image.PixelMap | string | 否 | 图片的像素数据或者图片路径地址(本地路径或网络路径)。 | +| publishDate | Date | 否 | 发行日期。 | +| subtitle | string | 否 | 子标题。 | +| description | string | 否 | 媒体描述。 | +| lyric | string | 否 | 歌词文件路径地址(本地路径或网络路径) | +| previousAssetId | string | 否 | 上一首媒体ID。 | +| nextAssetId | string | 否 | 下一首媒体ID。 | -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 | -| filter | Array\ | 'all' | 是 | 'all' 表示关注播放状态所有字段变化;Array 表示关注Array中的字段变化。 | -| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 是 | 回调函数,参数state是变化后的播放状态。 | +## AVMediaDescription10+ -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +播放列表媒体元数据的相关属性。 -| 错误码ID | 错误信息 | -| -------- | ------------------------------ | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**示例:** +| 名称 | 类型 | 必填 | 说明 | +| ------------ | ----------------------- | ---- | ----------------------- | +| mediaId | string | 是 | 播放列表媒体ID。 | +| title | string | 否 | 播放列表媒体标题。 | +| subtitle | string | 否 | 播放列表媒体子标题。 | +| description | string | 否 | 播放列表媒体描述的文本。 | +| icon | image.PixelMap | 否 | 播放列表媒体图片像素数据。 | +| iconUri | string | 否 | 播放列表媒体图片路径地址。 | +| extras | {[key: string]: any} | 否 | 播放列表媒体额外字段。 | +| mediaUri | string | 否 | 播放列表媒体URI。 | +| mediaType | string | 否 | 播放列表媒体类型。 | +| mediaSize | number | 否 | 播放列表媒体的大小。 | +| albumTitle | string | 否 | 播放列表媒体专辑标题。 | +| albumCoverUri | string | 否 | 播放列表媒体专辑标题URI。 | +| lyricContent | string | 否 | 播放列表媒体歌词内容。 | +| lyricUri | string | 否 | 播放列表媒体歌词URI。 | +| artist | string | 否 | 播放列表媒体专辑作者。 | +| fdSrc | media.AVFileDescriptor | 否 | 播放列表媒体本地文件的句柄。 | +| duration | number | 否 | 播放列表媒体播放时长。 | +| startPosition | number | 否 | 播放列表媒体起始播放位置。 | +| creditsPosition | number | 否 | 播放列表媒体的片尾播放位置。 | +| appName | string | 否 | 播放列表提供的应用的名字。 | -```js -controller.on('playbackStateChange', 'all', (playbackState) => { - console.info(`on playbackStateChange state : ${playbackState.state}`); -}); +## AVQueueItem10+ -let playbackFilter = ['state', 'speed', 'loopMode']; -controller.on('playbackStateChange', playbackFilter, (playbackState) => { - console.info(`on playbackStateChange state : ${playbackState.state}`); -}); -``` +播放列表中单项的相关属性。 -### on('sessionEvent')10+ +**系统能力:** SystemCapability.Multimedia.AVSession.Core -on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void +| 名称 | 类型 | 必填 | 说明 | +| ------------ | ------------------------------------------ | ---- | --------------------------- | +| itemId | number | 是 | 播放列表中单项的ID。 | +| description | [AVMediaDescription](#avmediadescription10) | 是 | 播放列表中单项的媒体元数据。 | + +## AVPlaybackState10+ + +媒体播放状态的相关属性。 + +**系统能力:** SystemCapability.Multimedia.AVSession.Core + +| 名称 | 类型 | 必填 | 说明 | +| ------------ | ------------------------------------- | ---- | ------- | +| state | [PlaybackState](#playbackstate) | 否 | 播放状态 | +| speed | number | 否 | 播放倍速 | +| position | [PlaybackPosition](#playbackposition) | 否 | 播放位置 | +| bufferedTime | number | 否 | 缓冲时间 | +| loopMode | [LoopMode](#loopmode10) | 否 | 循环模式 | +| isFavorite | boolean | 否 | 是否收藏 | +| activeItemId10+ | number | 否 | 正在播放的媒体Id | +| volume10+ | number | 否 | 正在播放的媒体音量 | +| extras10+ | {[key: string]: Object} | 否 | 自定义媒体数据 | + +## PlaybackPosition10+ -媒体控制器设置会话自定义事件变化的监听器。 +媒体播放位置的相关属性。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +| 名称 | 类型 | 必填 | 说明 | +| ----------- | ------ | ---- | ------------------ | +| elapsedTime | number | 是 | 已用时间,单位毫秒(ms)。 | +| updateTime | number | 是 | 更新时间,单位毫秒(ms)。 | -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'sessionEvent'`:当会话事件变化时,触发该事件。 | -| callback | (sessionEvent: string, args: {[key:string]: object}) => void | 是 | 回调函数,sessionEvent为变化的会话事件名,args为事件的参数。 | +## AVCastCategory10+ -**错误码:** +播放设备的类别枚举。 -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +**系统能力:** SystemCapability.Multimedia.AVSession.AVCast -| 错误码ID | 错误信息 | -| -------- | ------------------------------ | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +| 名称 | 值 | 说明 | +| --------------------------- | ---- | ----------- | +| CATEGORY_LOCAL | 0 | 本地播放,默认播放设备,声音从本机或者连接的蓝牙耳机设备出声。 | +| CATEGORY_REMOTE | 1 | 远端播放,远端播放设备,声音从其他设备发出声音或者画面。 | -**示例:** +## DeviceType10+ -```js -controller.on('sessionEvent', (sessionEvent, args) => { - console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); -}); -``` +播放设备的类型枚举。 -### on('queueItemsChange')10+ +**系统能力:** SystemCapability.Multimedia.AVSession.Core -on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void +| 名称 | 值 | 说明 | +| --------------------------- | ---- | ----------- | +| DEVICE_TYPE_LOCAL | 0 | 本地播放类型 | +| DEVICE_TYPE_BLUETOOTH | 10 | 蓝牙设备 | +| DEVICE_TYPE_TV | 2 | 电视
**系统能力:** SystemCapability.Multimedia.AVSession.AVCast | +| DEVICE_TYPE_SMART_SPEAKER | 3 | 音箱设备
**系统能力:** SystemCapability.Multimedia.AVSession.AVCast | -媒体控制器设置会话自定义播放列表变化的监听器。 +## DeviceInfo10+ + +播放设备的相关信息。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +| 名称 | 类型 | 必填 | 说明 | +| ---------- | -------------- | ---- | ---------------------- | +| castCategory | AVCastCategory | 是 | 播放设备的类别 | +| deviceId | string | 是 | 播放设备的ID。 | +| deviceName | string | 是 | 播放设备的名称。 | +| deviceType | DeviceType | 是 | 播放设备的类型。 | +| ipAddress | string | 否 | 播放设备的ip地址。
此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.AVSession.AVCast | +| providerId | number | 否 | 播放设备提供商。
此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.AVSession.AVCast | -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- | -| type | string | 是 | 事件回调类型,支持事件`'queueItemsChange'`:当session修改播放列表时,触发该事件。 | -| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 是 | 回调函数,items为变化的播放列表。 | +## OutputDeviceInfo10+ -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +播放设备的相关信息。 -| 错误码ID | 错误信息 | -| -------- | ------------------------------ | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**示例:** +| 名称 | 类型 | 必填 | 说明 | +| ---------- | -------------- | ---- | ---------------------- | +| devices | Array\ | 是 | 播放设备的集合。 | -```js -controller.on('queueItemsChange', (items) => { - console.info(`OnQueueItemsChange, items length is ${items.length}`); -}); -``` +## LoopMode10+ -### on('queueTitleChange')10+ +表示媒体播放循环模式的枚举。 -on(type: 'queueTitleChange', callback: (title: string) => void): void +**系统能力:** SystemCapability.Multimedia.AVSession.Core -媒体控制器设置会话自定义播放列表的名称变化的监听器。 +| 名称 | 值 | 说明 | +| ------------------ | ---- | -------- | +| LOOP_MODE_SEQUENCE | 0 | 顺序播放 | +| LOOP_MODE_SINGLE | 1 | 单曲循环 | +| LOOP_MODE_LIST | 2 | 表单循环 | +| LOOP_MODE_SHUFFLE | 3 | 随机播放 | -**系统能力:** SystemCapability.Multimedia.AVSession.Core +## PlaybackState10+ -**参数:** +表示媒体播放状态的枚举。 -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- | -| type | string | 是 | 事件回调类型,支持事件`'queueTitleChange'`:当session修改播放列表名称时,触发该事件。 | -| callback | (title: string) => void | 是 | 回调函数,title为变化的播放列表名称。 | +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +| 名称 | 值 | 说明 | +| --------------------------- | ---- | ----------- | +| PLAYBACK_STATE_INITIAL | 0 | 初始状态 | +| PLAYBACK_STATE_PREPARE | 1 | 播放准备状态 | +| PLAYBACK_STATE_PLAY | 2 | 正在播放 | +| PLAYBACK_STATE_PAUSE | 3 | 暂停 | +| PLAYBACK_STATE_FAST_FORWARD | 4 | 快进 | +| PLAYBACK_STATE_REWIND | 5 | 快退 | +| PLAYBACK_STATE_STOP | 6 | 停止 | +| PLAYBACK_STATE_COMPLETED | 7 | 播放完成 | +| PLAYBACK_STATE_RELEASED | 8 | 释放 | +| PLAYBACK_STATE_ERROR | 9 | 错误 | -| 错误码ID | 错误信息 | -| -------- | ------------------------------ | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +## AVSessionDescriptor -**示例:** +会话的相关描述信息。 -```js -controller.on('queueTitleChange', (title) => { - console.info(`queueTitleChange, title is ${title}`); -}); -``` +**系统能力:** SystemCapability.Multimedia.AVSession.Manager -### on('extrasChange')10+ +**系统接口:** 该接口为系统接口。 -on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void +| 名称 | 类型 | 可读 | 可写 | 说明 | +| --------------| ---------------- |-----|-----|------| +| sessionId | string | 是 | 否 | 会话ID | +| type | [AVSessionType](#avsessiontype10) | 是 | 否 | 会话类型 | +| sessionTag | string | 是 | 否 | 会话的自定义名称 | +| elementName | [ElementName](js-apis-bundle-ElementName.md) | 是 | 否 | 会话所属应用的信息(包含bundleName、abilityName等) | +| isActive | boolean | 是 | 否 | 会话是否被激活 | +| isTopSession | boolean | 是 | 否 | 会话是否为最新的会话 | +| outputDevice | [OutputDeviceInfo](#outputdeviceinfo10) | 是 | 否 | 分布式设备相关信息 | -媒体控制器设置自定义媒体数据包事件变化的监听器。 +## AVSessionController10+ -**系统能力:** SystemCapability.Multimedia.AVSession.Core +调用[avSession.createController](#avsessioncreatecontroller)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。 -**参数:** +### 属性 -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'extrasChange'`:当媒体提供方设置自定义媒体数据包时,触发该事件。 | -| callback | (extras: {[key:string]: object}) => void | 是 | 回调函数,extras为媒体提供方新设置的自定义媒体数据包,该自定义媒体数据包与dispatchSessionEvent方法设置的数据包完全一致。 | +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**错误码:** -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 +| 名称 | 类型 | 可读 | 可写 | 说明 | +| :-------- | :----- | :--- | :--- | :-------------------------------------- | +| sessionId | string | 是 | 否 | AVSessionController对象唯一的会话标识。 | -| 错误码ID | 错误信息 | -| -------- | ------------------------------ | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | **示例:** - ```js -controller.on('extrasChange', (extras) => { - console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); +let AVSessionController; +await avSession.createController(currentAVSession.sessionId).then((controller) => { + AVSessionController = controller; +}).catch((err) => { + console.error(`CreateController BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### on('sessionDestroy')10+ +### getAVPlaybackState10+ -on(type: 'sessionDestroy', callback: () => void) +getAVPlaybackState(callback: AsyncCallback\): void -会话销毁的监听事件。 +设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'sessionDestroy'`:当检测到会话销毁时,触发该事件)。 | -| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback<[[AVPlaybackState](#avplaybackstate10))\> | 是 | 回调函数,返回投播控制器实例。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ------------------------------ | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** ```js -controller.on('sessionDestroy', () => { - console.info(`on sessionDestroy : SUCCESS `); +AVSessionController.getAVPlaybackState(function (err, state) { + if (err) { + console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`getAVPlaybackState : SUCCESS`); + } }); ``` -### on('activeStateChange')10+ +### getAVPlaybackState10+ -on(type: 'activeStateChange', callback: (isActive: boolean) => void) +getAVPlaybackState(): Promise\; -会话的激活状态的监听事件。 +获取当前的远端播放状态。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | --------------------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'activeStateChange'`:当检测到会话的激活状态发生改变时,触发该事件。 | -| callback | (isActive: boolean) => void | 是 | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。 | +| 类型 | 说明 | +| --------- | ------------------------------------------------------------ | +| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise对象。返回投播控制器实例。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ----------------------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | -| 6600103 |The session controller does not exist. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.on('activeStateChange', (isActive) => { - console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`); +AVSessionController.getAVPlaybackState().then((state) => { + console.info(`getAVPlaybackState : SUCCESS :`); +}).catch((err) => { + console.error(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### on('validCommandChange')10+ +### getAVMetadata10+ -on(type: 'validCommandChange', callback: (commands: Array\) => void) +getAVMetadata(): Promise\ -会话支持的有效命令变化监听事件。 +获取会话元数据。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 | -| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 是 | 回调函数。参数commands是有效命令的集合。 | +| 类型 | 说明 | +| ----------------------------------- | ----------------------------- | +| Promise<[AVMetadata](#avmetadata10)\> | Promise对象,返回会话元数据。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ------------------------------ | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** - ```js -controller.on('validCommandChange', (validCommands) => { - console.info(`validCommandChange : SUCCESS : size : ${validCommands.size}`); - console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); +AVSessionController.getAVMetadata().then((metadata) => { + console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); +}).catch((err) => { + console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### on('outputDeviceChange')10+ +### getAVMetadata10+ -on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void +getAVMetadata(callback: AsyncCallback\): void -设置播放设备变化的监听事件。 +获取会话元数据。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件为`'outputDeviceChange'`:当播放设备变化时,触发该事件)。 | -| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 是 | 回调函数,参数device是设备相关信息。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback<[AVMetadata](#avmetadata10)\> | 是 | 回调函数,返回会话元数据。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ----------------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** - ```js -controller.on('outputDeviceChange', (state, device) => { - console.info(`on outputDeviceChange state: ${state}, device : ${device}`); +AVSessionController.getAVMetadata(function (err, metadata) { + if (err) { + console.error(`GetAVMetadata BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`GetAVMetadata : SUCCESS : assetId : ${metadata.assetId}`); + } }); ``` -### off('metadataChange')10+ +### getAVQueueTitle10+ -off(type: 'metadataChange', callback?: (data: AVMetadata) => void) +getAVQueueTitle(): Promise\ -媒体控制器取消监听元数据变化的事件。 +获取当前会话播放列表的名称。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | -| type | string | 是 | 取消对应的监听事件,支持事件`'metadataChange'`。 | -| callback | (data: [AVMetadata](#avmetadata10)) => void | 否 | 回调函数,参数data是变化后的元数据。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 类型 | 说明 | +| ---------------- | ----------------------------- | +| Promise | Promise对象。返回播放列表名称。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** - ```js -controller.off('metadataChange'); +AVSessionController.getAVQueueTitle().then((title) => { + console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); +}).catch((err) => { + console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### off('playbackStateChange')10+ +### getAVQueueTitle10+ -off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) +getAVQueueTitle(callback: AsyncCallback\): void -媒体控制器取消监听播放状态变化的事件。 +获取当前播放列表的名称。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'playbackStateChange'`。 | -| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 否 | 回调函数,参数state是变化后的播放状态。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------------------- | ---- | ------------------------- | +| callback | AsyncCallback | 是 | 回调函数,返回播放列表名称。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** - ```js -controller.off('playbackStateChange'); +AVSessionController.getAVQueueTitle(function (err, title) { + if (err) { + console.error(`GetAVQueueTitle BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`GetAVQueueTitle : SUCCESS : title : ${title}`); + } +}); ``` -### off('sessionEvent')10+ +### getAVQueueItems10+ -off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void +getAVQueueItems(): Promise\> -媒体控制器取消监听会话事件的变化通知。 +获取当前会话播放列表相关信息。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'sessionEvent'`。 | -| callback | (sessionEvent: string, args: {[key:string]: Object}) => void | 否 | 回调函数,参数sessionEvent是变化的事件名,args为事件的参数。
该参数为可选参数,若不填写该参数,则认为取消所有对sessionEvent事件的监听。 | +| 类型 | 说明 | +| --------------------------------------------- | ----------------------------- | +| Promise\> | Promise对象。返回播放列表队列。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** - ```js -controller.off('sessionEvent'); +AVSessionController.getAVQueueItems().then((items) => { + console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); +}).catch((err) => { + console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### off('queueItemsChange')10+ +### getAVQueueItems10+ -off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void +getAVQueueItems(callback: AsyncCallback\>): void -媒体控制器取消监听播放列表变化的事件。 +获取当前播放列表相关信息。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'queueItemsChange'`。 | -| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 否 | 回调函数,参数items是变化的播放列表。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------------------------------- | ---- | ------------------------- | +| callback | AsyncCallback\> | 是 | 回调函数,返回播放列表队列。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** - ```js -controller.off('queueItemsChange'); +AVSessionController.getAVQueueItems(function (err, items) { + if (err) { + console.error(`GetAVQueueItems BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`GetAVQueueItems : SUCCESS : length : ${items.length}`); + } +}); ``` -### off('queueTitleChange')10+ +### skipToQueueItem10+ -off(type: 'queueTitleChange', callback?: (title: string) => void): void +skipToQueueItem(itemId: number): Promise\ -媒体控制器取消监听播放列表名称变化的事件。 +设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'queueTitleChange'`。 | -| callback | (title: string) => void | 否 | 回调函数,参数items是变化的播放列表名称。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------- | ---- | ------------------------------------------- | +| itemId | number | 是 | 播放列表单项的ID值,用以表示选中的播放列表单项。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | --------------------------------------------------------------- | +| Promise\ | Promise对象。当播放列表单项ID设置成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** ```js -controller.off('queueTitleChange'); +let queueItemId = 0; +AVSessionController.skipToQueueItem(queueItemId).then(() => { + console.info(`SkipToQueueItem successfully`); +}).catch((err) => { + console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### off('extrasChange')10+ +### skipToQueueItem10+ -off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void +skipToQueueItem(itemId: number, callback: AsyncCallback\): void -媒体控制器取消监听自定义媒体数据包变化事件。 +设置指定播放列表单项的ID,发送给session端处理,session端可以选择对这个单项歌曲进行播放。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'extrasChange'`。 | -| callback | ({[key:string]: Object}) => void | 否 | 注册监听事件时的回调函数。
该参数为可选参数,若不填写该参数,则认为取消会话所有与此事件相关的监听。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------- | ---- | ----------------------------------------------------------- | +| itemId | number | 是 | 播放列表单项的ID值,用以表示选中的播放列表单项。 | +| callback | AsyncCallback\ | 是 | 回调函数。当播放状态设置成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | -| 6600101 | Session service exception. | +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | | 6600103 | The session controller does not exist. | **示例:** ```js -controller.off('extrasChange'); +let queueItemId = 0; +AVSessionController.skipToQueueItem(queueItemId, function (err) { + if (err) { + console.error(`SkipToQueueItem BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SkipToQueueItem successfully`); + } +}); ``` -### off('sessionDestroy')10+ +### getOutputDevice10+ -off(type: 'sessionDestroy', callback?: () => void) +getOutputDevice(): Promise\ -媒体控制器取消监听会话的销毁事件。 +获取播放设备信息。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------- | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'sessionDestroy'`。 | -| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 类型 | 说明 | +| ----------------------------------------------- | --------------------------------- | +| Promise<[OutputDeviceInfo](#outputdeviceinfo10)\> | Promise对象,返回播放设备信息。 | **错误码:** + 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +| -------- | ---------------------------------------- | +| 600101 | Session service exception. | +| 600103 | The session controller does not exist. | **示例:** - ```js -controller.off('sessionDestroy'); +AVSessionController.getOutputDevice().then((deviceInfo) => { + console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); +}).catch((err) => { + console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### off('activeStateChange')10+ +### getOutputDevice10+ -off(type: 'activeStateChange', callback?: (isActive: boolean) => void) +getOutputDevice(callback: AsyncCallback\): void -媒体控制器取消监听会话激活状态变化的事件。 +获取播放设备信息。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | --------------------------- | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'activeStateChange'`。 | -| callback | (isActive: boolean) => void | 否 | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------------------- | ---- | ------------------------------ | +| callback | AsyncCallback<[OutputDeviceInfo](#outputdeviceinfo10)\> | 是 | 回调函数,返回播放设备信息。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +| -------- | ---------------------------------------- | +| 600101 | Session service exception. | +| 600103 | The session controller does not exist. | **示例:** ```js -controller.off('activeStateChange'); +AVSessionController.getOutputDevice(function (err, deviceInfo) { + if (err) { + console.error(`GetOutputDevice BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`GetOutputDevice : SUCCESS : isRemote : ${deviceInfo.isRemote}`); + } +}); ``` -### off('validCommandChange')10+ +### sendAVKeyEvent10+ -off(type: 'validCommandChange', callback?: (commands: Array\) => void) +sendAVKeyEvent(event: KeyEvent): Promise\ -媒体控制器取消监听会话有效命令变化的事件。 +发送按键事件到控制器对应的会话。结果通过Promise异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'validCommandChange'`。 | -| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 否 | 回调函数。参数commands是有效命令的集合。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------------------------------------------------------------ | ---- | ---------- | +| event | [KeyEvent](js-apis-keyevent.md) | 是 | 按键事件。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -| 错误码ID | 错误信息 | -| -------- | ---------------- | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 600101 | Session service exception. | +| 600102 | The session does not exist. | +| 600103 | The session controller does not exist. | +| 600105 | Invalid session command. | +| 600106 | The session is not activated. | + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当事件发送成功,无返回结果,否则返回错误对象。 | **示例:** ```js -controller.off('validCommandChange'); +let keyItem = {code:0x49, pressedTime:2, deviceId:0}; +let event = {action:2, key:keyItem, keys:[keyItem]}; + +AVSessionController.sendAVKeyEvent(event).then(() => { + console.info(`SendAVKeyEvent Successfully`); +}).catch((err) => { + console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### off('outputDeviceChange')10+ +### sendAVKeyEvent10+ -off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void +sendAVKeyEvent(event: KeyEvent, callback: AsyncCallback\): void -媒体控制器取消监听分布式设备变化的事件。 +发送按键事件到会话。结果通过callback异步回调方式返回。 **系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | -| type | string | 是 | 取消对应的监听事件,支持事件`'outputDeviceChange'`。 | -| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 否 | 回调函数,参数device是设备相关信息。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ---------- | +| event | [KeyEvent](js-apis-keyevent.md) | 是 | 按键事件。 | +| callback | AsyncCallback\ | 是 | 回调函数。当事件发送成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -| 错误码ID | 错误信息 | -| -------- | ---------------- | -| 6600101 | Session service exception. | -| 6600103 | The session controller does not exist. | +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 600101 | Session service exception. | +| 600102 | The session does not exist. | +| 600103 | The session controller does not exist. | +| 600105 | Invalid session command. | +| 600106 | The session is not activated. | **示例:** ```js -controller.off('outputDeviceChange'); -``` - -## AVCastController10+ - -在投播建立后,调用[avSession.getAVCastController](#getavcastcontroller10)后,返回会话控制器实例。控制器可查看会话ID,并可完成对会话发送命令及事件,获取会话元数据,播放状态信息等操作。 +let keyItem = {code:0x49, pressedTime:2, deviceId:0}; +let event = {action:2, key:keyItem, keys:[keyItem]}; -### getAVPlaybackState10+ +AVSessionController.sendAVKeyEvent(event, function (err) { + if (err) { + console.error(`SendAVKeyEvent BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`SendAVKeyEvent Successfully`); + } +}); +``` -getAVPlaybackState(callback: AsyncCallback\): void +### getLaunchAbility10+ -设备建立连接后,获取投播控制器。结果通过callback异步回调方式返回。 +getLaunchAbility(): Promise\ -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +获取应用在会话中保存的WantAgent对象。结果通过Promise异步回调方式返回。 -**参数:** +**系统能力:** SystemCapability.Multimedia.AVSession.Core -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ | -| callback | AsyncCallback<[[AVPlaybackState](#avplaybackstate10))\> | 是 | 回调函数,返回投播控制器实例。 | +**返回值:** + +| 类型 | 说明 | +| ------------------------------------------------------- | ------------------------------------------------------------ | +| Promise<[WantAgent](js-apis-app-ability-wantAgent.md)\> | Promise对象,返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -5218,32 +5316,32 @@ getAVPlaybackState(callback: AsyncCallback\): void | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.getAVPlaybackState(function (err, state) { - if (err) { - console.info(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`getAVPlaybackState : SUCCESS`); - } +AVSessionController.getLaunchAbility().then((agent) => { + console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); +}).catch((err) => { + console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### getAVPlaybackState10+ +### getLaunchAbility10+ -getAVPlaybackState(): Promise\; +getLaunchAbility(callback: AsyncCallback\): void -获取当前的远端播放状态。结果通过callback异步回调方式返回。 +获取应用在会话中保存的WantAgent对象。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**返回值:** +**参数:** -| 类型 | 说明 | -| --------- | ------------------------------------------------------------ | -| Promise<[AVPlaybackState](#avplaybackstate10)\> | Promise对象。返回投播控制器实例。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback<[WantAgent](js-apis-app-ability-wantAgent.md)\> | 是 | 回调函数。返回在[setLaunchAbility](#setlaunchability10)保存的对象,包括应用的相关属性信息,如bundleName,abilityName,deviceId等。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 @@ -5251,1208 +5349,1167 @@ getAVPlaybackState(): Promise\; | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.getAVPlaybackState().then((state) => { - console.info(`getAVPlaybackState : SUCCESS :`); -}).catch((err) => { - console.info(`getAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); +AVSessionController.getLaunchAbility(function (err, agent) { + if (err) { + console.error(`GetLaunchAbility BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`GetLaunchAbility : SUCCESS : wantAgent : ${agent}`); + } }); ``` -### setDisplaySurface10+ - -setDisplaySurface(surfaceId: string): Promise\ +### getRealPlaybackPositionSync10+ -设置播放的surfaceId,在投播sink端使用。结果通过Promise异步回调方式返回。 +getRealPlaybackPositionSync(): number -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +获取当前播放位置。 -**系统接口:** 该接口为系统接口。 +**系统能力:** SystemCapability.Multimedia.AVSession.Core **返回值:** -| 类型 | 说明 | -| --------------------------------------------- | --------------------------- | -| Promise\ | Promise对象。返回设置结果。 | +| 类型 | 说明 | +| ------ | ------------------ | +| number | 时间节点,毫秒数。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600109 | The remote connection is not established. | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | +**示例:** -### setDisplaySurface10+ +```js +let time = AVSessionController.getRealPlaybackPositionSync(); +``` -setDisplaySurface(surfaceId: string, callback: AsyncCallback\): void +### isActive10+ -设置播放的surfaceId,在投播sink端使用。结果通过callback异步回调方式返回。 +isActive(): Promise\ -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +获取会话是否被激活。结果通过Promise异步回调方式返回。 -**系统接口:** 该接口为系统接口。 +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | --------------------------------------------------- | ---- | ---------------------------- | -| callback | AsyncCallback\ | 是 | 回调函数,返回当前设置结果。 | +| 类型 | 说明 | +| ----------------- | ------------------------------------------------------------ | +| Promise | Promise对象,返回会话是否为激活状态,true表示被激活,false表示禁用。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | -| 6600109 | The remote connection is not established. | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | **示例:** + ```js -controller.getAVPlaybackState(function (err, playbackState) { - if (err) { - console.info(`GetAVPlaybackState BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`GetAVPlaybackState : SUCCESS : state : ${playbackState.state}`); - } +AVSessionController.isActive().then((isActive) => { + console.info(`IsActive : SUCCESS : isactive : ${isActive}`); +}).catch((err) => { + console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); }); ``` -### on('playbackStateChange')10+ +### isActive10+ -on(type: 'playbackStateChange', filter: Array\ | 'all', callback: (state: AVPlaybackState) => void): void +isActive(callback: AsyncCallback\): void -设置播放状态变化的监听事件。 +判断会话是否被激活。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 | -| filter | Array\ | 'all' | 是 | 'all' 表示关注播放状态所有字段变化;Array 表示关注Array中的字段变化。 | -| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 是 | 回调函数,参数state是变化后的播放状态。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------- | ---- | ------------------------------------------------------------ | +| callback | AsyncCallback | 是 | 回调函数,返回会话是否为激活状态,true表示被激活,false表示禁用。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ------------------------------ | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.on('playbackStateChange', 'all', (playbackState) => { - console.info(`on playbackStateChange state : ${playbackState.state}`); -}); - -let playbackFilter = ['state', 'speed', 'loopMode']; -controller.on('playbackStateChange', playbackFilter, (playbackState) => { - console.info(`on playbackStateChange state : ${playbackState.state}`); +AVSessionController.isActive(function (err, isActive) { + if (err) { + console.error(`IsActive BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`IsActive : SUCCESS : isactive : ${isActive}`); + } }); ``` -### off('playbackStateChange')10+ +### destroy10+ -off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void): void +destroy(): Promise\ -媒体控制器取消监听播放状态变化的事件。 +销毁当前控制器,销毁后当前控制器不可再用。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'playbackStateChange'`。 | -| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 否 | 回调函数,参数state是变化后的播放状态。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当控制器销毁成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.off('playbackStateChange'); +AVSessionController.destroy().then(() => { + console.info(`Destroy : SUCCESS `); +}).catch((err) => { + console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### on('mediaItemChange')10+ +### destroy10+ -on(type: 'mediaItemChange', callback: Callback\): void +destroy(callback: AsyncCallback\): void -设置投播当前播放媒体内容的监听事件。 +销毁当前控制器,销毁后当前控制器不可再用。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'mediaItemChange'`:当播放状态变化时,触发该事件。 | -| callback | (state: [AVQueueItem](#avqueueitem10)) => void | 是 | 回调函数,参数AVQueueItem是d当前正在播放的媒体内容。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------- | ---- | ---------- | +| callback | AsyncCallback\ | 是 | 回调函数。当控制器销毁成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ------------------------------ | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.on('mediaItemChange', (item) => { - console.info(`on mediaItemChange state : ${item.itemId}`); +AVSessionController.destroy(function (err) { + if (err) { + console.error(`Destroy BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`Destroy : SUCCESS `); + } }); ``` -### off('mediaItemChange')10+ +### getValidCommands10+ -off(type: 'mediaItemChange'): void +getValidCommands(): Promise\> -取消设置投播当前播放媒体内容的监听事件。 +获取会话支持的有效命令。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'mediaItemChange'`。 | +| 类型 | 说明 | +| ------------------------------------------------------------ | --------------------------------- | +| Promise\> | Promise对象。返回有效命令的集合。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.off('mediaItemChange'); +AVSessionController.getValidCommands.then((validCommands) => { + console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); +}).catch((err) => { + console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### on('playNext')10+ +### getValidCommands10+ -on(type: 'playNext', callback: Callback\): void +getValidCommands(callback: AsyncCallback\>): void -设置播放下一首资源的监听事件。 +获取会话支持的有效命令。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'playNext'`:当播放下一首状态变化时,触发该事件。 | -| callback | Callback\ | 是 | 回调函数 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------ | +| callback | AsyncCallback\\> | 是 | 回调函数,返回有效命令的集合。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ------------------------------ | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.on('playNext', () => { - console.info(`on playNext`); +AVSessionController.getValidCommands(function (err, validCommands) { + if (err) { + console.error(`GetValidCommands BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`GetValidCommands : SUCCESS : size : ${validCommands.length}`); + } }); ``` -### off('playNext')10+ +### sendControlCommand10+ -off(type: 'playNext'): void +sendControlCommand(command: AVControlCommand): Promise\ -取消设置播放下一首资源的监听事件。 +通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +> **说明:** +> +> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[on'play'](#onplay10)、[on'pause'](#onpause10)等。 + +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'playNext'`。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| command | [AVControlCommand](#avcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600106 | The session is not activated. | +| 6600107 | Too many commands or events. | **示例:** ```js -controller.off('playNext'); +let avCommand = {command:'play'}; +// let avCommand = {command:'pause'}; +// let avCommand = {command:'stop'}; +// let avCommand = {command:'playNext'}; +// let avCommand = {command:'playPrevious'}; +// let avCommand = {command:'fastForward'}; +// let avCommand = {command:'rewind'}; +// let avCommand = {command:'seek', parameter:10}; +// let avCommand = {command:'setSpeed', parameter:2.6}; +// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; +// let avCommand = {command:'toggleFavorite', parameter:"false"}; +AVSessionController.sendControlCommand(avCommand).then(() => { + console.info(`SendControlCommand successfully`); +}).catch((err) => { + console.error(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### on('playPrevious')10+ +### sendControlCommand10+ + +sendControlCommand(command: AVControlCommand, callback: AsyncCallback\): void -on(type: 'playPrevious', callback: Callback\): void +通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。 -设置播放上一首资源的监听事件。 +> **说明:** +> +> 媒体控制方在使用sendControlCommand命令前,需要确保控制对应的媒体会话注册了对应的监听,注册媒体会话相关监听的方法请参见接口[on'play'](#onplay10)、[on'pause'](#onpause10)等。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'playPrevious'`:当播放下一首状态变化时,触发该事件。 | -| callback | Callback\ | 是 | 回调函数 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------- | ---- | ------------------------------ | +| command | [AVControlCommand](#avcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | +| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ------------------------------ | -| 6600101 | Session service exception. | +| -------- | ------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600106 | The session is not activated. | +| 6600107 | Too many commands or events. | **示例:** ```js -controller.on('playPrevious', () => { - console.info(`on playPrevious`); - // 设置播放参数,开始播放 - var playItem = { - itemId: 0, - description: { - mediaId: '12345', - mediaName: 'song1', - mediaType: 'AUDIO', - mediaUri: 'http://resource1_address', - mediaSize: 12345, - startPosition: 0, - duration: 0, - artist: 'mysong', - albumTitle: 'song1_title', - albumCoverUri: "http://resource1_album_address", - lyricUri: "http://resource1_lyric_address", - iconUri: "http://resource1_icon_address", - appName: 'MyMusic' - } - }; - // 准备播放,这个不会触发真正的播放,会进行加载和缓冲 - controller.prepare(playItem, () => { - console.info('prepare done'); - }); - // 启动播放 - controller.start(playItem, () => { - console.info('play done'); - }); +let avCommand = {command:'play'}; +// let avCommand = {command:'pause'}; +// let avCommand = {command:'stop'}; +// let avCommand = {command:'playNext'}; +// let avCommand = {command:'playPrevious'}; +// let avCommand = {command:'fastForward'}; +// let avCommand = {command:'rewind'}; +// let avCommand = {command:'seek', parameter:10}; +// let avCommand = {command:'setSpeed', parameter:2.6}; +// let avCommand = {command:'setLoopMode', parameter:avSession.LoopMode.LOOP_MODE_SINGLE}; +// let avCommand = {command:'toggleFavorite', parameter:"false"}; +AVSessionController.sendControlCommand(avCommand, function (err) { + if (err) { + console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.error(`SendControlCommand successfully`); + } }); ``` -### off('playPrevious')10+ +### sendCommonCommand10+ -off(type: 'playPrevious'): void +sendCommonCommand(command: string, args: {[key: string]: Object}): Promise\ -取消设置播放下一首资源的监听事件。 +通过会话控制器发送自定义控制命令到其对应的会话。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'playPrevious'`。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| command | string | 是 | 需要设置的自定义控制命令的名称 | +| args | {[key: string]: any} | 是 | 需要传递的控制命令键值对 | + +> **说明:** +> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md)。 + +**返回值:** + +| 类型 | 说明 | +| -------------- | ----------------------------- | +| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600106 | The session is not activated. | +| 6600107 | Too many commands or events. | **示例:** ```js -controller.off('playPrevious'); +let commandName = "my_command"; +let args = { + command : "This is my command" +} +await AVSessionController.sendCommonCommand(commandName, args).catch((err) => { + console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); +}) ``` -### on('seekDone')10+ +### sendCommonCommand10+ -on(type: 'seekDone', callback: Callback\): void +sendCommonCommand(command: string, args: {[key: string]: Object}, callback: AsyncCallback\): void -设置seek结束的监听事件。 +通过会话控制器发送自定义命令到其对应的会话。结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | -| type | string | 是 | 事件回调类型,支持事件`'seekDone'`:当seek结束时,触发该事件。 | -| callback | Callback\ | 是 | 回调函数,返回seek后播放的位置 | +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------------------------------------- | ---- | ------------------------------ | +| command | string | 是 | 需要设置的自定义控制命令的名称 | +| args | {[key: string]: any} | 是 | 需要传递的控制命令键值对 | +| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | + +> **说明:** +> 参数args支持的数据类型有:字符串、数字、布尔、对象、数组和文件描述符等,详细介绍请参见[@ohos.app.ability.Want(Want)](./js-apis-app-ability-want.md)。 **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ------------------------------ | -| 6600101 | Session service exception. | +| -------- | ------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600106 | The session is not activated. | +| 6600107 | Too many commands or events. | **示例:** ```js -controller.on('seekDone', (pos) => { - console.info(`on seekDone pos:${pos} `); -}); +let commandName = "my_command"; +let args = { + command : "This is my command" +} +AVSessionController.sendCommonCommand(commandName, args, (err) => { + if(err) { + console.info(`SendCommonCommand BusinessError: code: ${err.code}, message: ${err.message}`); + } +}) ``` -### off('seekDone')10+ +### getExtras10+ -off(type: 'seekDone'): void +getExtras(): Promise\<{[key: string]: Object}> -取消设置seek结束的监听事件。 +获取媒体提供方设置的自定义媒体数据包。结果通过Promise异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | -| type | string | 是 | 取消对应的监听事件,支持事件`'seekDone'`。 | +| 类型 | 说明 | +| ----------------------------------- | ----------------------------- | +| Promise<{[key: string]: Object}\> | Promise对象,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------- | +| -------- | ---------------------------------------- | | 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600107 | Too many commands or events. | **示例:** - ```js -controller.off('seekDone'); +let extras = await AVSessionController.getExtras().catch((err) => { + console.info(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); +}); ``` -### on('error')10+ +### getExtras10+ -on(type: 'error', callback: ErrorCallback): void +getExtras(callback: AsyncCallback\<{[key: string]: Object}>): void -监听远端播放器的错误事件,该事件仅用于错误提示,不需要用户停止播控动作。 +获取媒体提供方设置的自定义媒体数据包,结果通过callback异步回调方式返回。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | ---- | ------------------------------------------------------------ | -| type | string | 是 | 错误事件回调类型,支持的事件:'error',用户操作和系统都会触发此事件。 | -| callback | function | 是 | 错误事件回调方法:远端播放过程中发生的错误,会提供错误码ID和错误信息。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------- | ---- | -------------------------- | +| callback | AsyncCallback<{[key: string]: Object}\> | 是 | 回调函数,返回媒体提供方设置的自定义媒体数据包,数据包的内容与setExtras设置的内容完全一致。 | **错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-media.md)。 - -| 错误码ID | 错误信息 | -| -------- | --------------------- | -| 5400101 | No memory. | -| 5400102 | Operation not allowed. | -| 5400103 | I/O error. | -| 5400104 | Time out. | -| 5400105 | Service died. | -| 5400106 | Unsupport format. | +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------- | +| 6600101 | Session service exception. | +| 6600102 | The session does not exist. | +| 6600103 | The session controller does not exist. | +| 6600105 | Invalid session command. | +| 6600107 | Too many commands or events. | **示例:** - ```js -controller.on('error', (error) => { - console.error('error happened,and error message is :' + error.message) - console.error('error happened,and error code is :' + error.code) -}) +AVSessionController.getExtras(function (err, extras) { + if (err) { + console.error(`getExtras BusinessError: code: ${err.code}, message: ${err.message}`); + } else { + console.info(`getExtras : SUCCESS : assetId : ${metadata.assetId}`); + } +}); ``` -### off('error')10+ +### on('metadataChange')10+ -off(type: 'error'): void +on(type: 'metadataChange', filter: Array\ | 'all', callback: (data: AVMetadata) => void) -取消监听播放的错误事件。 +设置元数据变化的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ----------------------------------------- | -| type | string | 是 | 错误事件回调类型,取消注册的事件:'error' | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'metadataChange'`:当元数据变化时,触发该事件。 | +| filter | Array\ | 'all' | 是 | 'all' 表示关注元数据所有字段变化;Array 表示关注Array中的字段变化。 | +| callback | (data: [AVMetadata](#avmetadata10)) => void | 是 | 回调函数,参数data是变化后的元数据。 | **错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-media.md)。 - -| 错误码ID | 错误信息 | -| -------- | --------------------- | -| 5400101 | No memory. | -| 5400102 | Operation not allowed. | -| 5400103 | I/O error. | -| 5400104 | Time out. | -| 5400105 | Service died. | -| 5400106 | Unsupport format. | +| 错误码ID | 错误信息 | +| -------- | ------------------------------ | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | **示例:** ```js -controller.off('error') -``` - -### sendControlCommand10+ - -sendControlCommand(command: AVCastControlCommand): Promise\ - -通过控制器发送命令到其对应的会话。结果通过Promise异步回调方式返回。 +AVSessionController.on('metadataChange', 'all', (metadata) => { + console.info(`on metadataChange assetId : ${metadata.assetId}`); +}); +let metaFilter = ['assetId', 'title', 'description']; +AVSessionController.on('metadataChange', metaFilter, (metadata) => { + console.info(`on metadataChange assetId : ${metadata.assetId}`); +}); +``` -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +### off('metadataChange')10+ -**参数:** +off(type: 'metadataChange', callback?: (data: AVMetadata) => void) -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ------------------------------ | -| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | +媒体控制器取消监听元数据变化的事件。 -**返回值:** +**系统能力:** SystemCapability.Multimedia.AVSession.Core -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------ | +| type | string | 是 | 取消对应的监听事件,支持事件`'metadataChange'`。 | +| callback | (data: [AVMetadata](#avmetadata10)) => void | 否 | 回调函数,参数data是变化后的元数据。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | -| 6600105 | Invalid session command. | -| 6600109 | The remote connection is not established. | +| 6600103 | The session controller does not exist. | **示例:** ```js -let avCommand = {command:'play'}; -// let avCommand = {command:'pause'}; -// let avCommand = {command:'stop'}; -// let avCommand = {command:'playNext'}; -// let avCommand = {command:'playPrevious'}; -// let avCommand = {command:'fastForward'}; -// let avCommand = {command:'rewind'}; -// let avCommand = {command:'seek', parameter:10}; -controller.sendControlCommand(avCommand).then(() => { - console.info(`SendControlCommand successfully`); -}).catch((err) => { - console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); -}); +AVSessionController.off('metadataChange'); ``` -### sendControlCommand10+ - -sendControlCommand(command: AVCastControlCommand, callback: AsyncCallback\): void +### on('playbackStateChange')10+ -通过会话控制器发送命令到其对应的会话。结果通过callback异步回调方式返回。 +on(type: 'playbackStateChange', filter: Array\ | 'all', callback: (state: AVPlaybackState) => void) +设置播放状态变化的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------- | ---- | ------------------------------ | -| command | [AVCastControlCommand](#avcastcontrolcommand10) | 是 | 会话的相关命令和命令相关参数。 | -| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| --------| -----------|-----|------------| +| type | string | 是 | 事件回调类型,支持事件`'playbackStateChange'`:当播放状态变化时,触发该事件。 | +| filter | Array\ | 'all' | 是 | 'all' 表示关注播放状态所有字段变化;Array 表示关注Array中的字段变化。 | +| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 是 | 回调函数,参数state是变化后的播放状态。| **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | -| 6600105 | Invalid session command. | -| 6600109 | The remote connection is not established. | +| 6600103 | The session controller does not exist. | **示例:** ```js -let avCommand = {command:'play'}; -// let avCommand = {command:'pause'}; -// let avCommand = {command:'stop'}; -// let avCommand = {command:'playNext'}; -// let avCommand = {command:'playPrevious'}; -// let avCommand = {command:'fastForward'}; -// let avCommand = {command:'rewind'}; -// let avCommand = {command:'seek', parameter:10}; -controller.sendControlCommand(avCommand, function (err) { - if (err) { - console.info(`SendControlCommand BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`SendControlCommand successfully`); - } +AVSessionController.on('playbackStateChange', 'all', (playbackState) => { + console.info(`on playbackStateChange state : ${playbackState.state}`); +}); + +let playbackFilter = ['state', 'speed', 'loopMode']; +AVSessionController.on('playbackStateChange', playbackFilter, (playbackState) => { + console.info(`on playbackStateChange state : ${playbackState.state}`); }); ``` -### prepare10+ +### off('playbackStateChange')10+ -prepare(item: AVQueueItem, callback: AsyncCallback\): void +off(type: 'playbackStateChange', callback?: (state: AVPlaybackState) => void) -启动播放某个媒体资源。结果通过callback异步回调方式返回。 +媒体控制器取消监听播放状态变化的事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ------------------------------ | -| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | -| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'playbackStateChange'`。 | +| callback | (state: [AVPlaybackState](#avplaybackstate10)) => void | 否 | 回调函数,参数state是变化后的播放状态。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | **示例:** ```js -// 设置播放参数,开始播放 -var playItem = { - itemId: 0, - description: { - mediaId: '12345', - mediaName: 'song1', - mediaType: 'AUDIO', - mediaUri: 'http://resource1_address', - mediaSize: 12345, - startPosition: 0, - duration: 0, - artist: 'mysong', - albumTitle: 'song1_title', - albumCoverUri: "http://resource1_album_address", - lyricUri: "http://resource1_lyric_address", - iconUri: "http://resource1_icon_address", - appName: 'MyMusic' - } -}; -// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 -controller.prepare(playItem, () => { - console.info('prepare done'); -}); -// 启动播放 -controller.start(playItem, () => { - console.info('play done'); -}); +AVSessionController.off('playbackStateChange'); ``` +### on('sessionDestroy')10+ -### prepare10+ - -prepare(item: AVQueueItem): Promise\ - -启动播放某个媒体资源。结果通过Promise异步回调方式返回。 +on(type: 'sessionDestroy', callback: () => void) +会话销毁的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ------------------------------ | -| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | - -**返回值:** - -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'sessionDestroy'`:当检测到会话销毁时,触发该事件)。 | +| callback | () => void | 是 | 回调函数。当监听事件注册成功,err为undefined,否则为错误对象。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ------------------------------ | | 6600101 | Session service exception. | - +| 6600103 | The session controller does not exist. | **示例:** ```js -// 设置播放参数,开始播放 -var playItem = { - itemId: 0, - description: { - mediaId: '12345', - mediaName: 'song1', - mediaType: 'AUDIO', - mediaUri: 'http://resource1_address', - mediaSize: 12345, - startPosition: 0, - duration: 0, - artist: 'mysong', - albumTitle: 'song1_title', - albumCoverUri: "http://resource1_album_address", - lyricUri: "http://resource1_lyric_address", - iconUri: "http://resource1_icon_address", - appName: 'MyMusic' - } -}; -// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 -controller.prepare(playItem, () => { - console.info('prepare done'); -}); -// 启动播放 -controller.start(playItem).then(() => { - console.info(`start successfully`); -}).catch((err) => { - console.info(`start BusinessError: code: ${err.code}, message: ${err.message}`); +AVSessionController.on('sessionDestroy', () => { + console.info(`on sessionDestroy : SUCCESS `); }); ``` -### start10+ +### off('sessionDestroy')10+ -start(item: AVQueueItem, callback: AsyncCallback\): void +off(type: 'sessionDestroy', callback?: () => void) -启动播放某个媒体资源。结果通过callback异步回调方式返回。 +媒体控制器取消监听会话的销毁事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ------------------------------ | -| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | -| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------- | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'sessionDestroy'`。 | +| callback | () => void | 否 | 回调函数。当监听事件取消成功,err为undefined,否则返回错误对象。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ---------------- | | 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | **示例:** ```js -// 设置播放参数,开始播放 -var playItem = { -itemId: 0, -description: { - mediaId: '12345', - mediaName: 'song1', - mediaType: 'AUDIO', - mediaUri: 'http://resource1_address', - mediaSize: 12345, - startPosition: 0, - duration: 0, - artist: 'mysong', - albumTitle: 'song1_title', - albumCoverUri: "http://resource1_album_address", - lyricUri: "http://resource1_lyric_address", - iconUri: "http://resource1_icon_address", - appName: 'MyMusic' -} -}; -// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 -controller.prepare(playItem, () => { - console.info('prepare done'); -}); -// 启动播放 -controller.start(playItem, () => { - console.info('play done'); -}); +AVSessionController.off('sessionDestroy'); ``` +### on('activeStateChange')10+ -### start10+ - -start(item: AVQueueItem): Promise\ - -启动播放某个媒体资源。结果通过Promise异步回调方式返回。 +on(type: 'activeStateChange', callback: (isActive: boolean) => void) +会话的激活状态的监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------------------------- | ---- | ------------------------------ | -| item | [AVQueueItem](#avqueueitem10) | 是 | 播放列表中单项的相关属性。 | - -**返回值:** - -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当命令发送成功,无返回结果,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'activeStateChange'`:当检测到会话的激活状态发生改变时,触发该事件。 | +| callback | (isActive: boolean) => void | 是 | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ----------------------------- | | 6600101 | Session service exception. | - +| 6600103 |The session controller does not exist. | **示例:** ```js -// 设置播放参数,开始播放 -var playItem = { -itemId: 0, -description: { - mediaId: '12345', - mediaName: 'song1', - mediaType: 'AUDIO', - mediaUri: 'http://resource1_address', - mediaSize: 12345, - startPosition: 0, - duration: 0, - artist: 'mysong', - albumTitle: 'song1_title', - albumCoverUri: "http://resource1_album_address", - lyricUri: "http://resource1_lyric_address", - iconUri: "http://resource1_icon_address", - appName: 'MyMusic' -} -}; -// 准备播放,这个不会触发真正的播放,会进行加载和缓冲 -controller.prepare(playItem, () => { - console.info('prepare done'); -}); -// 启动播放 -controller.start(playItem).then(() => { - console.info(`start successfully`); -}).catch((err) => { - console.info(`start BusinessError: code: ${err.code}, message: ${err.message}`); +AVSessionController.on('activeStateChange', (isActive) => { + console.info(`on activeStateChange : SUCCESS : isActive ${isActive}`); }); ``` -### stopCasting10+ +### off('activeStateChange')10+ -stopCasting(callback: AsyncCallback\): void +off(type: 'activeStateChange', callback?: (isActive: boolean) => void) -结束投播。结果通过callback异步回调方式返回。 +媒体控制器取消监听会话激活状态变化的事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------- | ---- | ------------------------------------- | -| callback | AsyncCallback\ | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------- | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'activeStateChange'`。 | +| callback | (isActive: boolean) => void | 否 | 回调函数。参数isActive表示会话是否被激活。true表示被激活,false表示禁用。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600109 | The remote connection is not established. | +| -------- | ---------------- | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | **示例:** ```js -avSession.stopCasting(function (err) { - if (err) { - console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); - } else { - console.info(`stopCasting successfully`); - } -}); +AVSessionController.off('activeStateChange'); ``` -### stopCasting10+ +### on('validCommandChange')10+ -stopCasting(): Promise\ +on(type: 'validCommandChange', callback: (commands: Array\) => void) -结束投播。结果通过Promise异步回调方式返回。 +会话支持的有效命令变化监听事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core -**返回值:** +**参数:** -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\ | Promise对象。当停止投播索成功,无返回结果,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'validCommandChange'`:当检测到会话的合法命令发生改变时,触发该事件。 | +| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 是 | 回调函数。参数commands是有效命令的集合。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | -| 6600109 | The remote connection is not established. | +| -------- | ------------------------------ | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | **示例:** ```js -avSession.stopCasting().then(() => { - console.info(`stopCasting successfully`); -}).catch((err) => { - console.info(`stopCasting BusinessError: code: ${err.code}, message: ${err.message}`); +AVSessionController.on('validCommandChange', (validCommands) => { + console.info(`validCommandChange : SUCCESS : size : ${validCommands.size}`); + console.info(`validCommandChange : SUCCESS : validCommands : ${validCommands.values()}`); }); ``` -### getCurrentItem10+ +### off('validCommandChange')10+ -getCurrentItem(callback: AsyncCallback\): void +off(type: 'validCommandChange', callback?: (commands: Array\) => void) -获取当前投播的资源信息。结果通过callback异步回调方式返回。 +媒体控制器取消监听会话有效命令变化的事件。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**系统能力:** SystemCapability.Multimedia.AVSession.Core **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------------------------- | ---- | ------------------------------------- | -| callback | AsyncCallback\<[AVQueueItem](#avqueueitem10)> | 是 | 回调函数。当命令发送成功,err为undefined,否则返回错误对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'validCommandChange'`。 | +| callback | (commands: Array<[AVControlCommandType](#avcontrolcommandtype10)\>) => void | 否 | 回调函数。参数commands是有效命令的集合。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -| 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| 错误码ID | 错误信息 | +| -------- | ---------------- | | 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | +**示例:** -### getCurrentItem10+ +```js +AVSessionController.off('validCommandChange'); +``` -getCurrentItem(): Promise\ +### on('outputDeviceChange')10+ -结束投播。结果通过Promise异步回调方式返回。 +on(type: 'outputDeviceChange', callback: (state: ConnectionState, device: OutputDeviceInfo) => void): void -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +设置播放设备变化的监听事件。 -**返回值:** +**系统能力:** SystemCapability.Multimedia.AVSession.Core -| 类型 | 说明 | -| -------------- | ----------------------------- | -| Promise\<[AVQueueItem](#avqueueitem10)> | Promise对象,返回当前的播放资源,否则返回错误对象。 | +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件为`'outputDeviceChange'`:当播放设备变化时,触发该事件)。 | +| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 是 | 回调函数,参数device是设备相关信息。 | **错误码:** 以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 | 错误码ID | 错误信息 | -| -------- | ---------------------------------------- | +| -------- | ----------------------- | | 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | +**示例:** -## SessionToken +```js +AVSessionController.on('outputDeviceChange', (state, device) => { + console.info(`on outputDeviceChange state: ${state}, device : ${device}`); +}); +``` -会话令牌的信息。 +### off('outputDeviceChange')10+ -**需要权限:** ohos.permission.MANAGE_MEDIA_RESOURCES,仅系统应用可用。 +off(type: 'outputDeviceChange', callback?: (state: ConnectionState, device: OutputDeviceInfo) => void): void -**系统能力:** SystemCapability.Multimedia.AVSession.Manager +媒体控制器取消监听分布式设备变化的事件。 -**系统接口:** 该接口为系统接口。 +**系统能力:** SystemCapability.Multimedia.AVSession.Core -| 名称 | 类型 | 必填 | 说明 | -| :-------- | :----- | :--- | :----------- | -| sessionId | string | 是 | 会话ID | -| pid | number | 否 | 会话的进程ID | -| uid | number | 否 | 用户ID | +**参数:** -## AVSessionType10+ -当前会话支持的会话类型。 +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------- | ---- | ------------------------------------------------------ | +| type | string | 是 | 取消对应的监听事件,支持事件`'outputDeviceChange'`。 | +| callback | (state: [ConnectionState](#connectionstate10), device: [OutputDeviceInfo](#outputdeviceinfo10)) => void | 否 | 回调函数,参数device是设备相关信息。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -| 名称 | 类型 | 说明 | -| ----- | ------ | ---- | -| audio | string | 音频 | -| video | string | 视频 | +| 错误码ID | 错误信息 | +| -------- | ---------------- | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -## AVSessionDescriptor +**示例:** -会话的相关描述信息。 +```js +AVSessionController.off('outputDeviceChange'); +``` -**系统能力:** SystemCapability.Multimedia.AVSession.Manager +### on('sessionEvent')10+ -**系统接口:** 该接口为系统接口。 +on(type: 'sessionEvent', callback: (sessionEvent: string, args: {[key:string]: Object}) => void): void -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ------------ | ------------------------------------------------------------ | ---- | --------------------------------------------------- | --------------------------------------------------- | -| sessionId | string | 是 | 否 | 会话ID | -| type | [AVSessionType](#avsessiontype10) | 是 | 否 | 会话类型 | -| sessionTag | string | 是 | 否 | 会话的自定义名称 | -| elementName | [ElementName](js-apis-bundle-ElementName.md) | 是 | 否 | 会话所属应用的信息(包含bundleName、abilityName等) | -| isActive | boolean | 是 | 否 | 会话是否被激活 | -| isTopSession | boolean | 是 | 否 | 会话是否为最新的会话 | -| outputDevice | [OutputDeviceInfo](#outputdeviceinfo10) | 是 | 否 | 分布式设备相关信息 | +媒体控制器设置会话自定义事件变化的监听器。 -## AVControlCommandType10+ +**系统能力:** SystemCapability.Multimedia.AVSession.Core -会话可传递的命令。 +**参数:** -**系统能力:** SystemCapability.Multimedia.AVSession.Core +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'sessionEvent'`:当会话事件变化时,触发该事件。 | +| callback | (sessionEvent: string, args: {[key:string]: object}) => void | 是 | 回调函数,sessionEvent为变化的会话事件名,args为事件的参数。 | -| 名称 | 类型 | 说明 | -| -------------- | ------ | ------------ | -| play | string | 播放 | -| pause | string | 暂停 | -| stop | string | 停止 | -| playNext | string | 下一首 | -| playPrevious | string | 上一首 | -| fastForward | string | 快进 | -| rewind | string | 快退 | -| seek | string | 跳转某一节点 | -| setSpeed | string | 设置播放倍速 | -| setLoopMode | string | 设置循环模式 | -| toggleFavorite | string | 是否收藏 | +**错误码:** -## AVControlCommand10+ +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -会话接受的命令的对象描述。 +| 错误码ID | 错误信息 | +| -------- | ------------------------------ | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**示例:** -| 名称 | 类型 | 必填 | 说明 | -| --------- | ------------------------------------------------- | ---- | -------------- | -| command | [AVControlCommandType](#avcontrolcommandtype10) | 是 | 命令 | -| parameter | [LoopMode](#loopmode10) | string | number | 否 | 命令对应的参数 | +```js +AVSessionController.on('sessionEvent', (sessionEvent, args) => { + console.info(`OnSessionEvent, sessionEvent is ${sessionEvent}, args: ${JSON.stringify(args)}`); +}); +``` -## AVCastControlCommandType10+ +### off('sessionEvent')10+ -投播控制器可传递的命令。 +off(type: 'sessionEvent', callback?: (sessionEvent: string, args: {[key:string]: Object}) => void): void -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +媒体控制器取消监听会话事件的变化通知。 -| 名称 | 类型 | 说明 | -| -------------- | ------ | ------------ | -| play | string | 播放 | -| pause | string | 暂停 | -| stop | string | 停止 | -| playNext | string | 下一首 | -| playPrevious | string | 上一首 | -| fastForward | string | 快进 | -| rewind | string | 快退 | -| seek | numbder | 跳转某一节点 | -| setSpeed | number | 设置播放倍速 | -| setLoopMode | string | 设置循环模式 | -| toggleFavorite | string | 是否收藏 | -| setVolume | number | 设置音量 | +**系统能力:** SystemCapability.Multimedia.AVSession.Core -## AVCastControlCommand10+ +**参数:** -投播控制器接受的命令的对象描述。 +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'sessionEvent'`。 | +| callback | (sessionEvent: string, args: {[key:string]: Object}) => void | 否 | 回调函数,参数sessionEvent是变化的事件名,args为事件的参数。
该参数为可选参数,若不填写该参数,则认为取消所有对sessionEvent事件的监听。 | -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -| 名称 | 类型 | 必填 | 说明 | -| --------- | ------------------------------------------------- | ---- | -------------- | -| command | [AVCastControlCommandType](#avcastcontrolcommandtype10) | 是 | 命令 | -| parameter | [LoopMode](#loopmode10) | string | number | 否 | 命令对应的参数 | +| 错误码ID | 错误信息 | +| -------- | ---------------- | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -## AVMetadata10+ +**示例:** -媒体元数据的相关属性。 +```js +AVSessionController.off('sessionEvent'); +``` + +### on('queueItemsChange')10+ + +on(type: 'queueItemsChange', callback: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void + +媒体控制器设置会话自定义播放列表变化的监听器。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -| 名称 | 类型 | 必填 | 说明 | -| --------------- |-------------------------| ---- |---------------------------------------------------------------------| -| assetId | string | 是 | 媒体ID。 | -| title | string | 否 | 标题。 | -| artist | string | 否 | 艺术家。 | -| author | string | 否 | 专辑作者。 | -| album | string | 否 | 专辑名称。 | -| writer | string | 否 | 词作者。 | -| composer | string | 否 | 作曲者。 | -| duration | number | 否 | 媒体时长,单位毫秒(ms)。 | -| mediaImage | image.PixelMap | string | 否 | 图片的像素数据或者图片路径地址(本地路径或网络路径)。 | -| publishDate | Date | 否 | 发行日期。 | -| subtitle | string | 否 | 子标题。 | -| description | string | 否 | 媒体描述。 | -| lyric | string | 否 | 歌词文件路径地址(本地路径或网络路径) | -| previousAssetId | string | 否 | 上一首媒体ID。 | -| nextAssetId | string | 否 | 下一首媒体ID。 | +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------------------------------------- | ---- | ---------------------------------------------------------------------------- | +| type | string | 是 | 事件回调类型,支持事件`'queueItemsChange'`:当session修改播放列表时,触发该事件。 | +| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 是 | 回调函数,items为变化的播放列表。 | -## AVMediaDescription10+ +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -播放列表媒体元数据的相关属性。 +| 错误码ID | 错误信息 | +| -------- | ------------------------------ | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -**系统能力:** SystemCapability.Multimedia.AVSession.Core +**示例:** -| 名称 | 类型 | 必填 | 说明 | -| ------------ | ----------------------- | ---- | ----------------------- | -| mediaId | string | 是 | 播放列表媒体ID。 | -| title | string | 否 | 播放列表媒体标题。 | -| subtitle | string | 否 | 播放列表媒体子标题。 | -| description | string | 否 | 播放列表媒体描述的文本。 | -| icon | image.PixelMap | 否 | 播放列表媒体图片像素数据。 | -| iconUri | string | 否 | 播放列表媒体图片路径地址。 | -| extras | {[key: string]: any} | 否 | 播放列表媒体额外字段。 | -| mediaUri | string | 否 | 播放列表媒体URI。 | -| mediaType | string | 否 | 播放列表媒体类型。 | -| mediaSize | number | 否 | 播放列表媒体的大小。 | -| albumTitle | string | 否 | 播放列表媒体专辑标题。 | -| albumCoverUri | string | 否 | 播放列表媒体专辑标题URI。 | -| lyricContent | string | 否 | 播放列表媒体歌词内容。 | -| lyricUri | string | 否 | 播放列表媒体歌词URI。 | -| artist | string | 否 | 播放列表媒体专辑作者。 | -| fdSrc | media.AVFileDescriptor | 否 | 播放列表媒体本地文件的句柄。 | -| duration | number | 否 | 播放列表媒体播放时长。 | -| startPosition | number | 否 | 播放列表媒体起始播放位置。 | -| creditsPosition | number | 否 | 播放列表媒体的片尾播放位置。 | -| appName | string | 否 | 播放列表提供的应用的名字。 | +```js +AVSessionController.on('queueItemsChange', (items) => { + console.info(`OnQueueItemsChange, items length is ${items.length}`); +}); +``` -## AVQueueItem10+ +### off('queueItemsChange')10+ -播放列表中单项的相关属性。 +off(type: 'queueItemsChange', callback?: (items: Array<[AVQueueItem](#avqueueitem10)\>) => void): void + +媒体控制器取消监听播放列表变化的事件。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -| 名称 | 类型 | 必填 | 说明 | -| ------------ | ------------------------------------------ | ---- | --------------------------- | -| itemId | number | 是 | 播放列表中单项的ID。 | -| description | [AVMediaDescription](#avmediadescription10) | 是 | 播放列表中单项的媒体元数据。 | +**参数:** -## AVPlaybackState10+ +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ---------------------------------------------------- | ---- | --------------------------------------------------------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'queueItemsChange'`。 | +| callback | (items: Array<[AVQueueItem](#avqueueitem10)\>) => void | 否 | 回调函数,参数items是变化的播放列表。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | -媒体播放状态的相关属性。 +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +| 错误码ID | 错误信息 | +| -------- | ---------------- | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -| 名称 | 类型 | 必填 | 说明 | -| ------------ | ------------------------------------- | ---- | ------- | -| state | [PlaybackState](#playbackstate) | 否 | 播放状态 | -| speed | number | 否 | 播放倍速 | -| position | [PlaybackPosition](#playbackposition) | 否 | 播放位置 | -| bufferedTime | number | 否 | 缓冲时间 | -| loopMode | [LoopMode](#loopmode10) | 否 | 循环模式 | -| isFavorite | boolean | 否 | 是否收藏 | -| activeItemId10+ | number | 否 | 正在播放的媒体Id | -| volume10+ | number | 否 | 正在播放的媒体音量 | -| extras10+ | {[key: string]: Object} | 否 | 自定义媒体数据 | +**示例:** -## PlaybackPosition10+ +```js +AVSessionController.off('queueItemsChange'); +``` -媒体播放位置的相关属性。 +### on('queueTitleChange')10+ + +on(type: 'queueTitleChange', callback: (title: string) => void): void + +媒体控制器设置会话自定义播放列表的名称变化的监听器。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -| 名称 | 类型 | 必填 | 说明 | -| ----------- | ------ | ---- | ------------------ | -| elapsedTime | number | 是 | 已用时间,单位毫秒(ms)。 | -| updateTime | number | 是 | 更新时间,单位毫秒(ms)。 | +**参数:** -## AVCastCategory10+ +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------- | +| type | string | 是 | 事件回调类型,支持事件`'queueTitleChange'`:当session修改播放列表名称时,触发该事件。 | +| callback | (title: string) => void | 是 | 回调函数,title为变化的播放列表名称。 | -播放设备的类别枚举。 +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +| 错误码ID | 错误信息 | +| -------- | ------------------------------ | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -| 名称 | 值 | 说明 | -| --------------------------- | ---- | ----------- | -| CATEGORY_LOCAL | 0 | 本地播放,默认播放设备,声音从本机或者连接的蓝牙耳机设备出声。 | -| CATEGORY_REMOTE | 1 | 远端播放,远端播放设备,声音从其他设备发出声音或者画面。 | +**示例:** -## ConnectionState10+ +```js +AVSessionController.on('queueTitleChange', (title) => { + console.info(`queueTitleChange, title is ${title}`); +}); +``` -播放设备的类别枚举。 +### off('queueTitleChange')10+ + +off(type: 'queueTitleChange', callback?: (title: string) => void): void + +媒体控制器取消监听播放列表名称变化的事件。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -| 名称 | 值 | 说明 | -| --------------------------- | ---- | ----------- | -| STATE_CONNECTING | 0 | 设备连接中 | -| STATE_CONNECTED | 1 | 设备连接成功 | -| STATE_DISCONNECTED | 6 | 设备断开连接 | +**参数:** -## ProtocolType10+ +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'queueTitleChange'`。 | +| callback | (title: string) => void | 否 | 回调函数,参数items是变化的播放列表名称。
该参数为可选参数,若不填写该参数,则认为取消所有相关会话的事件监听。 | -远端设备支持的协议类型。 +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -**系统能力:** SystemCapability.Multimedia.AVSession.AVCast +| 错误码ID | 错误信息 | +| -------- | ---------------- | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -**系统接口:** 该接口为系统接口。 +**示例:** -| 名称 | 值 | 说明 | -| --------------------------- | ---- | ----------- | -| TYPE_LOCAL | 0 | 本地设备 | -| TYPE_CAST_PLUS_MIRROR | 1 | Cast+的镜像模式 | -| TYPE_CAST_PLUS_STREAM | 2 | Cast+的Stream模式 | +```js +AVSessionController.off('queueTitleChange'); +``` -## DeviceType10+ +### on('extrasChange')10+ -播放设备的类型枚举。 +on(type: 'extrasChange', callback: (extras: {[key:string]: Object}) => void): void + +媒体控制器设置自定义媒体数据包事件变化的监听器。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -| 名称 | 值 | 说明 | -| --------------------------- | ---- | ----------- | -| DEVICE_TYPE_LOCAL | 0 | 本地播放类型 | -| DEVICE_TYPE_BLUETOOTH | 10 | 蓝牙设备 | -| DEVICE_TYPE_TV | 2 | 电视
**系统能力:** SystemCapability.Multimedia.AVSession.AVCast | -| DEVICE_TYPE_SMART_SPEAKER | 3 | 音箱设备
**系统能力:** SystemCapability.Multimedia.AVSession.AVCast | +**参数:** -## DeviceInfo10+ +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | +| type | string | 是 | 事件回调类型,支持事件`'extrasChange'`:当媒体提供方设置自定义媒体数据包时,触发该事件。 | +| callback | (extras: {[key:string]: object}) => void | 是 | 回调函数,extras为媒体提供方新设置的自定义媒体数据包,该自定义媒体数据包与dispatchSessionEvent方法设置的数据包完全一致。 | -播放设备的相关信息。 +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +| 错误码ID | 错误信息 | +| -------- | ------------------------------ | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -| 名称 | 类型 | 必填 | 说明 | -| ---------- | -------------- | ---- | ---------------------- | -| castCategory | AVCastCategory | 是 | 播放设备的类别 | -| deviceId | string | 是 | 播放设备的ID。 | -| deviceName | string | 是 | 播放设备的名称。 | -| deviceType | DeviceType | 是 | 播放设备的类型。 | -| ipAddress | string | 否 | 播放设备的ip地址。
此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.AVSession.AVCast | -| providerId | number | 否 | 播放设备提供商。
此接口为系统接口。
**系统能力:** SystemCapability.Multimedia.AVSession.AVCast | +**示例:** -## OutputDeviceInfo10+ +```js +AVSessionController.on('extrasChange', (extras) => { + console.info(`Caught extrasChange event,the new extra is: ${JSON.stringify(extras)}`); +}); +``` -播放设备的相关信息。 +### off('extrasChange')10+ + +off(type: 'extrasChange', callback?: (extras: {[key:string]: Object}) => void): void + +媒体控制器取消监听自定义媒体数据包变化事件。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -| 名称 | 类型 | 必填 | 说明 | -| ---------- | -------------- | ---- | ---------------------- | -| devices | Array\ | 是 | 播放设备的集合。 | +**参数:** -## PlaybackState10+ +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ----------------------- | ---- | ------------------------------------------------------------------------------------------------------- | +| type | string | 是 | 取消对应的监听事件,支持事件`'extrasChange'`。 | +| callback | ({[key:string]: Object}) => void | 否 | 注册监听事件时的回调函数。
该参数为可选参数,若不填写该参数,则认为取消会话所有与此事件相关的监听。 | -表示媒体播放状态的枚举。 +**错误码:** +以下错误码的详细介绍请参见[媒体会话管理错误码](../errorcodes/errorcode-avsession.md)。 -**系统能力:** SystemCapability.Multimedia.AVSession.Core +| 错误码ID | 错误信息 | +| -------- | ---------------- | +| 6600101 | Session service exception. | +| 6600103 | The session controller does not exist. | -| 名称 | 值 | 说明 | -| --------------------------- | ---- | ----------- | -| PLAYBACK_STATE_INITIAL | 0 | 初始状态 | -| PLAYBACK_STATE_PREPARE | 1 | 播放准备状态 | -| PLAYBACK_STATE_PLAY | 2 | 正在播放 | -| PLAYBACK_STATE_PAUSE | 3 | 暂停 | -| PLAYBACK_STATE_FAST_FORWARD | 4 | 快进 | -| PLAYBACK_STATE_REWIND | 5 | 快退 | -| PLAYBACK_STATE_STOP | 6 | 停止 | -| PLAYBACK_STATE_COMPLETED | 7 | 播放完成 | -| PLAYBACK_STATE_RELEASED | 8 | 释放 | -| PLAYBACK_STATE_ERROR | 9 | 错误 | +**示例:** +```js +AVSessionController.off('extrasChange'); +``` -## LoopMode10+ +## AVControlCommandType10+ -表示媒体播放循环模式的枚举。 +会话可传递的命令。 **系统能力:** SystemCapability.Multimedia.AVSession.Core -| 名称 | 值 | 说明 | -| ------------------ | ---- | -------- | -| LOOP_MODE_SEQUENCE | 0 | 顺序播放 | -| LOOP_MODE_SINGLE | 1 | 单曲循环 | -| LOOP_MODE_LIST | 2 | 表单循环 | -| LOOP_MODE_SHUFFLE | 3 | 随机播放 | +| 名称 | 类型 | 说明 | +| -------------- | ------ | ------------ | +| play | string | 播放 | +| pause | string | 暂停 | +| stop | string | 停止 | +| playNext | string | 下一首 | +| playPrevious | string | 上一首 | +| fastForward | string | 快进 | +| rewind | string | 快退 | +| seek | string | 跳转某一节点 | +| setSpeed | string | 设置播放倍速 | +| setLoopMode | string | 设置循环模式 | +| toggleFavorite | string | 是否收藏 | + +## AVControlCommand10+ + +会话接受的命令的对象描述。 + +**系统能力:** SystemCapability.Multimedia.AVSession.Core + +| 名称 | 类型 | 必填 | 说明 | +| --------- | ------------------------------------------------- | ---- | -------------- | +| command | [AVControlCommandType](#avcontrolcommandtype10) | 是 | 命令 | +| parameter | [LoopMode](#loopmode10) | string | number | 否 | 命令对应的参数 | ## AVSessionErrorCode10+ @@ -6471,5 +6528,3 @@ getCurrentItem(): Promise\ | ERR_CODE_MESSAGE_OVERLOAD | 6600107 | Too many commands or events. | | ERR_CODE_DEVICE_CONNECTION_FAILED | 6600108 | Device connecting failed. | | ERR_CODE_REMOTE_CONNECTION_NOT_EXIST | 6600109 | The remote connection is not established. | - -