diff --git a/zh-cn/application-dev/reference/apis/js-apis-audio.md b/zh-cn/application-dev/reference/apis/js-apis-audio.md index ed2c521ace2e1f25f7ac493fade668b8a8c1c637..01ec48911898f3ae2be5b72eb17152cce9a69ba3 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-audio.md +++ b/zh-cn/application-dev/reference/apis/js-apis-audio.md @@ -4461,6 +4461,156 @@ off(type: 'preferredOutputDeviceChangeForRendererInfo', callback?: Callback10+ + +getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo, callback: AsyncCallback<AudioDeviceDescriptors>): void + +根据音频信息,返回优先级最高的输入设备,使用callback方式异步返回结果。 + +**系统能力:** SystemCapability.Multimedia.Audio.Device + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------------------------- | ------------------------------------------------------------ | ---- | ------------------------- | +| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | 是 | 表示采集器信息。 | +| callback | AsyncCallback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 是 | 回调,返回优先级最高的输入设备信息。 | + +**错误码:** + +以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。 + +| 错误码ID | 错误信息 | +| ------- | --------------------------------------------| +| 6800101 | if input parameter value error | +| 6800301 | System error | + +**示例:** +```js +let capturerInfo = { + source: audio.SourceType.SOURCE_TYPE_MIC, + capturerFlags: 0 +} + +audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo, (err, desc) => { + if (err) { + console.error(`Result ERROR: ${err}`); + } else { + console.info(`device descriptor: ${desc}`); + } +}); +``` + +### getPreferredInputDeviceForCapturerInfo10+ + +getPreferredInputDeviceForCapturerInfo(capturerInfo: AudioCapturerInfo): Promise<AudioDeviceDescriptors> + +根据音频信息,返回优先级最高的输入设备,使用promise方式异步返回结果。 + +**系统能力:** SystemCapability.Multimedia.Audio.Device + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ----------------------| ------------------------------------------------------------ | ---- | ------------------------- | +| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | 是 | 表示采集器信息。 | + +**返回值:** + +| 类型 | 说明 | +| --------------------- | --------------------------- | +| Promise<[AudioDeviceDescriptors](#audiodevicedescriptors)> | Promise返回优先级最高的输入设备信息。 | + +**错误码:** + +以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。 + +| 错误码ID | 错误信息 | +| ------- | --------------------------------------------| +| 6800101 | if input parameter value error | +| 6800301 | System error | + +**示例:** + +```js +let capturerInfo = { + source: audio.SourceType.SOURCE_TYPE_MIC, + capturerFlags: 0 +} + +audioRoutingManager.getPreferredInputDeviceForCapturerInfo(capturerInfo).then((desc) => { + console.info(`device descriptor: ${desc}`); +}).catch((err) => { + console.error(`Result ERROR: ${err}`); +}) +``` + +### on('preferredInputDeviceChangeForCapturerInfo')10+ + +on(type: 'preferredInputDeviceChangeForCapturerInfo', capturerInfo: AudioCapturerInfo, callback: Callback): void + +订阅最高优先级输入设备变化事件,使用callback获取最高优先级输入设备。 + +**系统能力:** SystemCapability.Multimedia.Audio.Device + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| :------- | :--------------------------------------------------- | :--- | :----------------------------------------- | +| type | string | 是 | 订阅的事件的类型。支持事件:'preferredInputDeviceChangeForCapturerInfo' | +| capturerInfo | [AudioCapturerInfo](#audiocapturerinfo8) | 是 | 表示采集器信息。 | +| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)\> | 是 | 获取优先级最高的输入设备信息。 | + +**错误码:** + +以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。 + +| 错误码ID | 错误信息 | +| ------- | --------------------------------------------| +| 6800101 | if input parameter value error | + +**示例:** + +```js +let capturerInfo = { + source: audio.SourceType.SOURCE_TYPE_MIC, + capturerFlags: 0 +} + +audioRoutingManager.on('preferredInputDeviceChangeForCapturerInfo', capturerInfo, (desc) => { + console.info(`device descriptor: ${desc}`); +}); +``` + +### off('preferredInputDeviceChangeForCapturerInfo')10+ + +off(type: 'preferredInputDeviceChangeForCapturerInfo', callback?: Callback): void + +取消订阅最高优先级输入音频设备变化事件。 + +**系统能力:** SystemCapability.Multimedia.Audio.Device + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | --------------------------------------------------- | ---- | ------------------------------------------ | +| type | string | 是 | 订阅的事件的类型。支持事件:'preferredInputDeviceChangeForCapturerInfo' | +| callback | Callback<[AudioDeviceDescriptors](#audiodevicedescriptors)> | 否 | 监听方法的回调函数。 | + +**错误码:** + +以下错误码的详细介绍请参见[音频错误码](../errorcodes/errorcode-audio.md)。 + +| 错误码ID | 错误信息 | +| ------- | --------------------------------------------| +| 6800101 | if input parameter value error | + +**示例:** + +```js +audioRoutingManager.off('preferredInputDeviceChangeForCapturerInfo'); +``` + ## AudioRendererChangeInfoArray9+ 数组类型,AudioRenderChangeInfo数组,只读。