Solve the problem that the volume is not automatically switched when the headset device is plugged in

Signed-off-by: fangzheng24 <fangzheng24@huawei.com>
This commit is contained in:
fangzheng24 2023-01-29 11:23:28 +08:00
parent aed5f8218b
commit 6fd1fc2413

View File

@ -50,6 +50,18 @@ export async function registerObserver(){
AppStorage.SetOrCreate('volume_media', data.volume);
}
})
audioManager.on('deviceChange', () => {
audioManager.getVolume(Audio.AudioVolumeType.RINGTONE,(err,data)=>{
AppStorage.SetOrCreate('volume_ringtone', data);
})
audioManager.getVolume(Audio.AudioVolumeType.VOICE_CALL,(err,data)=>{
AppStorage.SetOrCreate('volume_voicecall', data);
})
audioManager.getVolume(Audio.AudioVolumeType.MEDIA,(err,data)=>{
AppStorage.SetOrCreate('volume_media', data);
})
})
}