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
215 stars 13 forks source link

iOS + Expo unexpected results #34

Open OwenMelbz opened 1 month ago

OwenMelbz commented 1 month ago

Hi, Sorry this is not a bug as such.

We're using Expo and want:

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

hirbod commented 1 month ago

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.

OwenMelbz commented 1 month ago

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

hirbod commented 1 month ago
    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.