From 9bd85bbb838214bcf787bbbcd1c591d90f30e045 Mon Sep 17 00:00:00 2001 From: zhangkai Date: Wed, 8 Jan 2025 16:47:56 +0800 Subject: [PATCH] =?UTF-8?q?cherry=20pick=2097ca627=20from=20https://gitee.?= =?UTF-8?q?com/zhangkai269/docs=5F3/pulls/69137=20audio=20=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E6=80=A7=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangkai --- .../reference/apis-audio-kit/js-apis-audio.md | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/zh-cn/application-dev/reference/apis-audio-kit/js-apis-audio.md b/zh-cn/application-dev/reference/apis-audio-kit/js-apis-audio.md index 8e512642833..4ef9e98ad89 100644 --- a/zh-cn/application-dev/reference/apis-audio-kit/js-apis-audio.md +++ b/zh-cn/application-dev/reference/apis-audio-kit/js-apis-audio.md @@ -3213,6 +3213,46 @@ audioVolumeGroupManager.on('micStateChange', (micStateChange: audio.MicStateChan }); ``` +### off('micStateChange')12+ + +off(type: 'micStateChange', callback?: Callback<MicStateChangeEvent>): void + +取消监听系统麦克风状态更改事件,使用callback方式返回结果。 + +**系统能力:** SystemCapability.Multimedia.Audio.Volume + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------------------------------------- |----| ------------------------------------------------------------ | +| type | string | 是 | 监听事件,固定为:'micStateChange'。 | +| callback | Callback<[MicStateChangeEvent](#micstatechangeevent9)> | 否 | 回调函数,返回变更后的麦克风状态。 | + +**错误码:** + +以下错误码的详细介绍请参见[Audio错误码](errorcode-audio.md)。 + +| 错误码ID | 错误信息 | +| ------- | --------------------------------------------| +| 401 | Parameter error. Possible causes: 1.Mandatory parameters missing; 2.Incorrect parameter types. | +| 6800101 | Parameter verification failed. | + +**示例:** + +```ts +// 取消该事件的所有监听 +audioVolumeGroupManager.off('micStateChange'); + +// 同一监听事件中,on方法和off方法传入callback参数一致,off方法取消对应on方法订阅的监听 +let micStateChangeCallback = (micStateChange: audio.MicStateChangeEvent) => { + console.info(`Current microphone status is: ${micStateChange.mute} `); +}); + +audioVolumeGroupManager.on('micStateChange', micStateChangeCallback); + +audioVolumeGroupManager.off('micStateChange', micStateChangeCallback); +``` + ### isVolumeUnadjustable10+ isVolumeUnadjustable(): boolean -- Gitee