hirbod / react-native-volume-manager

React Native module which adds the ability to change the system volume on iOS and Android, listen to volume changes and supress the native volume UI to build your own volume slider or UX. It can listen to iOS mute switch and ringer mode changes on Android (and let you set the ringer mode)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

addVolumeListener is not triggered on iOS

SN99LZ opened this issue · comments

Hello,
on iOS 15 addVolumeListener is NOT triggered when the volume is changed with a slider or when physical volume buttons are pressed on a device.

OS version:
15.6.1
"react-native": "0.67.5"

Please provide a MVCE.

I created a useEffect with a simple code as explained in the docs
it works on Android but not on IOS :
(REAL DEVICES)

useEffect(() => {
const volumeListener = VolumeManager.addVolumeListener((result) => {
console.log('##### Volume changed ##### ', result.volume)
setVolumeLevel(result.volume);
});

return () => {
volumeListener.remove();
}
}, []);

Are you using a video library like expo-av or react-native-video? If yes, did you try to change the audio mode?
https://github.com/hirbod/react-native-volume-manager#ios-audio-session-management

No i don't use a video library but somehow it works now thanks for the help.

@SN99LZ what did you use to make it work? Ran into the same issue with the hook setup.

commented

@saaymeen did you make sure to have the newest version installed?

Hi @hirbod, I am on 1.8.0. Any way to debug the module?

commented

Are you trying it inside an iOS Simulator? This module only works on a real device. Android Emulator works if API Level 33+

I am using it on a real iPad Pro 2018 model, but I had a call with a colleague running an parallel and when I disconnect the call and restart the app, it works. Sorry for the inconvenience, I missed that detail.
Could it work while being in a call tho?

commented

I've honestly never tested that case. It might work depending on the Audio Session and Audio Category.
This library has multiple setters (setCategory and setMode). With the right combination I am pretty sure it should work (mixWithOthers might be worth a shot)