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)
MIT License
216 stars 13 forks source link

addVolumeListener is not triggered on iOS #7

Closed SN99LZ closed 1 year ago

SN99LZ commented 1 year ago

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"

hirbod commented 1 year ago

Please provide a MVCE.

SN99LZ commented 1 year ago

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(); } }, []);

hirbod commented 1 year ago

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

SN99LZ commented 1 year ago

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

saaymeen commented 10 months ago

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

hirbod commented 10 months ago

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

saaymeen commented 10 months ago

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

hirbod commented 10 months ago

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

saaymeen commented 10 months ago

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?

hirbod commented 10 months ago

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)