未验证 提交 471a8691 编写于 作者: O openharmony_ci 提交者: Gitee

!19029 最高优先级输出设备查询

Merge pull request !19029 from wangtao/mas_526
......@@ -45,16 +45,14 @@ audioRoutingManager.getDevices(audio.DeviceFlag.OUTPUT_DEVICES_FLAG).then((data)
```ts
// 监听音频设备状态变化
audioRoutingManager.on('deviceChange', audio.DeviceFlag.OUTPUT_DEVICES_FLAG, (deviceChanged) => {
console.info('device change type : ' + deviceChanged.type); // 设备连接状态变化,0为连接,1为断开连接
console.info('device descriptor size : ' + deviceChanged.deviceDescriptors.length);
console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceRole); // 设备角色
console.info('device change descriptor : ' + deviceChanged.deviceDescriptors[0].deviceType); // 设备类型
console.info(`device change type : ${deviceChanged.type}`); // 设备连接状态变化,0为连接,1为断开连接
console.info(`device descriptor size : ${deviceChanged.deviceDescriptors.length}`);
console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceRole}`); // 设备角色
console.info(`device change descriptor : ${deviceChanged.deviceDescriptors[0].deviceType}`); // 设备类型
});
// 取消监听音频设备状态变化
audioRoutingManager.off('deviceChange', (deviceChanged) => {
console.info('Should be no callback.');
});
audioRoutingManager.off('deviceChange');
```
## 选择音频输出设备(仅对系统应用开放)
......@@ -88,3 +86,46 @@ async function selectOutputDevice(){
});
}
```
## 获取最高优先级输设备信息
使用getPreferOutputDeviceForRendererInfo()方法, 可以获取当前最高优先级的输出设备。
> **说明:**
>
> 最高优先级输出设备表示声音将在此设备输出的设备。
```ts
let rendererInfo = {
content : audio.ContentType.CONTENT_TYPE_MUSIC,
usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
rendererFlags : 0,
}
async function getPreferOutputDeviceForRendererInfo() {
audioRoutingManager.getPreferOutputDeviceForRendererInfo(rendererInfo).then((desc) => {
console.info(`device descriptor: ${desc}`);
}).catch((err) => {
console.error(`Result ERROR: ${err}`);
})
}
```
## 监听最高优先级输出设备变化
```ts
let rendererInfo = {
content : audio.ContentType.CONTENT_TYPE_MUSIC,
usage : audio.StreamUsage.STREAM_USAGE_MEDIA,
rendererFlags : 0,
}
// 监听最高优先级输出设备变化
audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', rendererInfo, (desc) => {
console.info(`device change descriptor : ${desc.deviceDescriptors[0].deviceRole}`); // 设备角色
console.info(`device change descriptor : ${desc.deviceDescriptors[0].deviceType}`); // 设备类型
});
// 取消监听最高优先级输出设备变化
audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo');
```
......@@ -2083,9 +2083,7 @@ off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
**示例:**
```js
audioManager.off('deviceChange', (deviceChanged) => {
console.info('Should be no callback.');
});
audioManager.off('deviceChange');
```
### on('interrupt')
......@@ -3484,9 +3482,7 @@ off(type: 'deviceChange', callback?: Callback<DeviceChangeAction\>): void
**示例:**
```js
audioRoutingManager.off('deviceChange', (deviceChanged) => {
console.info('Should be no callback.');
});
audioRoutingManager.off('deviceChange');
```
### selectInputDevice<sup>9+</sup>
......@@ -4038,9 +4034,7 @@ off(type: 'preferOutputDeviceChangeForRendererInfo', callback?: Callback<AudioDe
**示例:**
```js
audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo', () => {
console.info('Should be no callback.');
});
audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo');
```
## AudioRendererChangeInfoArray<sup>9+</sup>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册