Closed youniaogu closed 7 months ago
The reason is most likely that you're losing the audio session. You could try using the AppState
listener to disable the AudioSession
when you background the app and then enable it once you reopen the app. To do this, call:
VolumeManager.enable(true)
Alternatively, you can use VolumeManager.setActive(true)
or false
based on the app's state.
Im one of my Apps, I am doing following:
const onAppStateChange = useCallback(async (status: AppStateStatus) => {
if (status === 'active') {
if (audioSessionIsInactive.current) {
VolumeManager.setActive(true);
audioSessionIsInactive.current = false;
}
} else if (status === 'background') {
VolumeManager.setActive(false);
audioSessionIsInactive.current = true;
}
}, []);
useAppState({
onChange: onAppStateChange,
});
Based on what libraries you use, you might need to trigger .enable(true)
as well. Check the methods in the README, that should help to solve your issue.
Thank you for the reply
I call the VolumeManager.enable(true)
and it worked!
my case is use volume up/down event to control flatlist scroll prev/next, so i make a
useVolumeUpDown
hook based on addVolumeListenerand my problem is if the app get in background and switch to other app(i reproduce by use youtube), play video and back to app, the listener will never trigger
so is the volume listener have conflict with other app listener?
below is my code and use case: