【问题标题】:How to get the volume level information in React Native如何在 React Native 中获取音量级别信息
【发布时间】:2020-05-12 04:14:28
【问题描述】:

我想在 React native 中获取设备的静音/增加/减少声音事件。

【问题讨论】:

  • 非常感谢您的回答。不使用库可以吗?
  • 你已经为它集成了模块。在图书馆里面。
  • 是的。非常感谢您的帮助。这解决了我的问题。 @KiritModi 兄弟。

标签: react-native


【解决方案1】:

您可以使用react-native-system-setting库来设置音量。

import SystemSetting from 'react-native-system-setting'

...

SystemSetting.setVolume(0.5);

还可以获取当前音量:

SystemSetting.getVolume().then(currentVolume => console.log(currentVolume));

或者听听变化:

useEffect(() => {
    const volumeListener = SystemSetting.addVolumeListener(data => {
        console.log(data.volume);
    });

    return () => SystemSetting.removeVolumeListener(volumeListener)  
}, [])

感谢@Kirit-Modi 的评论。

【讨论】:

    猜你喜欢
    • 2021-11-22
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 2019-09-07
    相关资源
    最近更新 更多