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

iOS: importing library stops music playing before opening the app #30

Closed matiastucci closed 3 months ago

matiastucci commented 3 months ago

I have music playing on Spotify, and when I open my react native app it stops. I debugged my code and ended up realizing that by just importing this library it happens: e.g import { setVolume } from 'react-native-volume-manager'

hirbod commented 3 months ago

Hi,

are you referring to iOS? Usually, we're not setting / starting an audio session unless you've registered a listener or manually called an audio session, but I'll take a look at it soon, as I need to prepare some updates for RN 0.73.

Meanwhile you could try to set a category and specially have a look for the mixWithOthers bool?

matiastucci commented 3 months ago

I tried this on a fresh react native app and the bug doesn't happen. I noticed that in my actual app, I have react-native-track-player installed and having both libraries causes this. Specifically when calling setupPlayer. I tried passing a mixWithOthers option but no luck. Any ideas what could be happening? Thanks!

hirbod commented 3 months ago

Unfortunately, things start to get tricky when you use third-party modules that also require an audio session. In the past, I encountered similar issues with expo-av and react-native-video. I had to patch out the audio session management from these libraries and ensure that the audio session was registered with the React Native Volume Manager.

RNTP is actually a pretty decent library and also has plenty of the same functions that this library has. https://rntp.dev/docs/3.2/api/constants/ios-category-options

You should setupPlayer with the correct Category and allow mixWithOthers or make sure to use the ambient category when calling setupPlayer: https://rntp.dev/docs/3.2/api/constants/ios-category

matiastucci commented 3 months ago

Oh, I didn't try with ambient before. Apparently, that did the trick! Thanks!