Skip to content

Commit 03ee8be

Browse files
committed
feat: JoinAudioChannel路由监听做了调整
1 parent 7780d12 commit 03ee8be

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

HarmonyOS_NEXT/APIExample/entry/src/main/ets/pages/basic/JoinAudioChannel.ets

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ struct JoinAudioChannel {
4949
private channelProfileType = Constants.ChannelProfile.COMMUNICATION
5050
private audioScenarioType = Constants.AudioScenarioType.DEFAULT
5151
private audioProfileType = Constants.AudioProfileType.DEFAULT
52-
52+
private routerChangeListener = (desc: audio.AudioDeviceDescriptors) => {
53+
//https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-audio-V5#devicetype
54+
Logger.info(TAG, `路由切换 设备类型 : ${desc[0].deviceType}`);
55+
}
5356
@Builder
5457
customPickerBuilder(): void {
5558
Image($r('app.media.ic_connect'))
@@ -189,15 +192,11 @@ struct JoinAudioChannel {
189192
//注册路由监听
190193
this.audioRoutingManager.on('preferOutputDeviceChangeForRendererInfo', {
191194
usage: audio.StreamUsage.STREAM_USAGE_VOICE_COMMUNICATION, rendererFlags: 0
192-
}, (desc: audio.AudioDeviceDescriptors) => {
193-
//https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-audio-V5#devicetype
194-
//这个回调不是很及时
195-
Logger.info(TAG, `路由切换 设备类型 : ${desc[0].deviceType}`);
196-
});
195+
}, this.routerChangeListener);
197196
}
198197

199198
aboutToDisappear(): void {
200-
this.audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo')
199+
this.audioRoutingManager.off('preferOutputDeviceChangeForRendererInfo',this.routerChangeListener)
201200
if (this.rtcEngine != undefined) {
202201
if (this.isJoin) {
203202
this.rtcEngine.leaveChannel();
@@ -309,7 +308,7 @@ struct JoinAudioChannel {
309308

310309
Column({ space: 5 }) {
311310
Row() {
312-
Text('鸿蒙音频输出设备切换的API')
311+
Text('')
313312
Button((this.isJoin && !this.isMicophotoOpen) ? $r('app.string.open_microphone') :
314313
$r('app.string.close_microphone'))
315314
.onClick(this.handleMicospeakerClick)

0 commit comments

Comments
 (0)