react-native-volume-manager
react-native-volume-manager copied to clipboard
iOS + Expo unexpected results
Hi, Sorry this is not a bug as such.
We're using Expo and want:
- Audio from other apps to continue, e.g. spotify, twitch, youtube, etc.
- Audio to play from our app even when in silent mode
- To detect when silent mode is turned off/on
We used expo originally and had it working fine with:
import { Audio } from 'expo-av'
await Audio.setAudioModeAsync({
allowsRecordingIOS: false,
staysActiveInBackground: true,
playsInSilentModeIOS: true,
shouldDuckAndroid: true,
interruptionModeIOS: InterruptionModeIOS.DuckOthers,
interruptionModeAndroid: InterruptionModeAndroid.DuckOthers,
})
We then added the following after the above ^^
await VolumeManager.enable(true, false)
await VolumeManager.enableInSilenceMode(true)
VolumeManager.addSilentListener(({ isMuted }) => {
setState(isMuted)
})
However this seems to pause all audio from other apps when our app boots.
What would be the correct usage to enable what's mentioned above?
Thanks
Unfortunately, VolumeManager and expo-av are not compatible without patching expo-av. We had to do the same in our app before we ultimately switched to Amazon IVS Player for React Native.
Expo-av (and some other components like react-native-video) hijack the audio session and forcefully reset it upon foregrounding/backgrounding. When I used expo-av, I had to remove the audio session management by Expo and use my own library to have more granular control over when I set the audio mode and when I clear the listeners.
We're not locked into using expo-av, if we were to drop it, how would we replicate the above expo-av settings using this package?
Thanks
allowsRecordingIOS: false, // Not implemented in this package
staysActiveInBackground: true, // This works out-of-the-box if the background music entitlement is active
playsInSilentModeIOS: true, // There is a method for this in the package
shouldDuckAndroid: true, // Not implemented in this package
interruptionModeIOS: InterruptionModeIOS.DuckOthers, // Implemented, check setMode/setCategory
interruptionModeAndroid: InterruptionModeAndroid.DuckOthers, // Not implemented in this package
Android hasn't been the primary focus in this package yet. I'll try to address the missing features for Android, but my free time is very limited currently. I can't give any ETA, but contributions via pull requests would be greatly appreciated.