xiqi / react-native-live-audio-stream

Get live audio stream data for React Native (works for iOS and Android)
MIT License
86 stars 36 forks source link

iOS - Volume going down after recording sound #17

Open LunatiqueCoder opened 2 years ago

LunatiqueCoder commented 2 years ago

👋 Hello!

Thank you for this great library! Really solved all our issues.

🪲 PROBLEM:

We're using this library along with react-native-video and react-native-sound, and when we record, the volume is going down. This wouldn't be such a great deal, but it gets stuck at a lower level.

⭐️ SOLUTION

Followed this solution https://stackoverflow.com/a/27020411/14056591

Applied it here (line 33 and 38): https://github.com/xiqi/react-native-live-audio-stream/blob/master/ios/RNLiveAudioStream.m#L33 https://github.com/xiqi/react-native-live-audio-stream/blob/master/ios/RNLiveAudioStream.m#L38

Changed AVAudioSessionCategoryOptionDuckOthers to AVAudioSessionCategoryOptionDefaultToSpeaker

This would be the diff:

--- a/node_modules/react-native-live-audio-stream/ios/RNLiveAudioStream.m
+++ b/node_modules/react-native-live-audio-stream/ios/RNLiveAudioStream.m
     if (@available(iOS 10.0, *)) {
         success = [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord
                                        mode: AVAudioSessionModeVoiceChat
-                                    options: AVAudioSessionCategoryOptionDuckOthers |
+                                    options: AVAudioSessionCategoryOptionDefaultToSpeaker |
                                              AVAudioSessionCategoryOptionAllowBluetooth |
                                              AVAudioSessionCategoryOptionAllowAirPlay
                                       error: &error];
     } else {
-        success = [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions: AVAudioSessionCategoryOptionDuckOthers error: &error];
+        success = [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions: AVAudioSessionCategoryOptionDefaultToSpeaker error: &error];
         success = [audioSession setMode: AVAudioSessionModeVoiceChat error: &error] && success;
     }
     if (!success || error != nil) {

This issue body was partially generated by patch-package.

qsdnedzid commented 2 years ago

@criszz77 That alone didn't work for me, I also had to change audioSession mode to AVAudioSessionModeDefault instead of AVAudioSessionModeVoiceChat . But your changes also helped, thank you!

matthewtoast commented 1 year ago

I'm still seeing the volume reduced when I make all of the above recommended changes. It isn't as bad as before - but it still goes down... maybe to about half of what it was initially. @qsdnedzid did you have to make any further changes other than what you mentioned?