zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 747 forks source link

iPhone in silent: enableInSilenceMode and setCategory not working #91

Closed anshul-kai closed 7 years ago

anshul-kai commented 7 years ago

enableInSilenceMode and setCategory are no longer available. After looking at details here and reading up other posts, I'm still having trouble making sounds work when iPhone is in silent mode.

The code below returns successfully but sound doesn't play in silent mode.

NSError *setCategoryError = nil;
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (!success) { /* handle the error condition */ }

NSError *activationError = nil;
success = [audioSession setActive:YES error:&activationError];
if (!success) { /* handle the error condition */ }

Any suggestions?

andrewmtam commented 7 years ago

I found that github references version 8.4 of the plugin ( which includes enableInSilenceMode and setCategory ), whereas the version on npm (8.3) does not yet have this functionality.

To get around, I just cloned this git repo into my node_modules, instead of npm install. There is probably a cleaner way to do that, but that's what is working for me.

anshul-kai commented 7 years ago

Thanks @andrew-tam-000! I feel like an idiot to have not noticed that.

To use npm i, just replace your package.json with the following. It is the same as cloning master.

Package.json "react-native-sound": "github:zmxv/react-native-sound"

FWIW, enableInSilenceMode is still not working for me but using setCategory('Playback') works and does the same thing.

I'll leave this open for the devs to address npm issues.

andrewmtam commented 7 years ago

No problem @a-koka! It also took me forever to figure it out... so just spreading the love XD.

And awesome, I've wondered how to do that git cloning via npm for the longest time, thanks!

benvium commented 7 years ago

I've made it clearer in the docs that enableInSilenceMode is deprecated and setCategory is the way to go now.