本文介绍了如何在 React Native 中获取音量级别信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在 React Native 中获取设备静音/增加/减少声音事件的事件.
I would like to get the event of device's mute/increase/decrease sound event in React native.
推荐答案
你可以使用 react-native-system-setting 库来设置音量.
you can use react-native-system-setting library to set the volume.
import SystemSetting from 'react-native-system-setting'
...
SystemSetting.setVolume(0.5);
您还可以获取当前音量:
You can also get the current volume:
SystemSetting.getVolume().then(currentVolume => console.log(currentVolume));
或者听听变化:
useEffect(() => {
const volumeListener = SystemSetting.addVolumeListener(data => {
console.log(data.volume);
});
return () => SystemSetting.removeVolumeListener(volumeListener)
}, [])
感谢@Kirit-Modi 的评论.
Thanks @Kirit-Modi, for his comment.
这篇关于如何在 React Native 中获取音量级别信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!