Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ducking Others Audios #652

Open
4 of 8 tasks
AlexisChup opened this issue Feb 24, 2020 · 6 comments
Open
4 of 8 tasks

Ducking Others Audios #652

AlexisChup opened this issue Feb 24, 2020 · 6 comments
Labels

Comments

@AlexisChup
Copy link

AlexisChup commented Feb 24, 2020

🪲 Description

Ducking (lower the volume from) others audios in background.

🪲 What is the observed behavior?

The audio from other app (like Spotify) and from react-native-sound(RNS) are mix together, however there are at the same volume :

  1. The user put some music, from Spotify for example.
  2. The user come to my app and launch the game ( about every 3 minute a name is called).
  3. When a name is called from RNS audio, the Spotify's audio and RNS audio are at the same volume.

🪲 What is the expected behavior?

  1. The user put some music, from Spotify for example.
  2. The user come to my app and launch the game ( about every 3 minute a name is called).
  3. When a name is called from RNS audio, the Spotify's audio would be ducked.
  4. At the end of RNS audio, the Spotify's audio will be set at his normal volume.

🪲 Please post your code:

// The Sounds object 
    let whoosh;

// Import the react-native-sound module
    let Sound = require('react-native-sound');

// Enable playback in silence mode, mixWithOthers and background
    Sound.setCategory('Playback', true);
    Sound.setMode('SpokenAudio');

// What is called every 3 minute
    var whoosh = new Sound('./audios/actions/saxo.mp3', Sound.MAIN_BUNDLE, (error) => {
      if (error) {
        console.log('failed to load the sound', error);
        return;
      }
      // Play the sound with an onEnd callback
      whoosh.play((success) => {
        if (success) {
          console.log('successfully finished playing, go for another lauch TimeOut');
          this._launchTimeOut();
        } else {
          console.log('playback failed due to audio decoding errors');
        }
      });
    });

💡 Does the problem have a test case?

  1. Create a RNS object
  2. Put some music, from Spotify for example
  3. Launch RNS audio
  4. Confirm that duck is not working

💡 Possible solution

Maybe it would be possible that I didn't use the right mode when I called

Sound.setMode()

But I tried every mode they have :

//"Default", "VoiceChat", "VideoChat", "GameChat", "VideoRecording", "Measurement", "MoviePlayback", "SpokenAudio".

Or Maybe it would be possible that it was for this function

Sound.setCategory()

But I also tried every mode they have :

//"Ambient", "SoloAmbient", "Playback", "Record", "PlayAndRecord", "AudioProcessing", "MultiRoute".

💡 Is there a workaround?

I tried a lot of things but I completly stuck. If anyone succeeds to duck other audios in background it would be perfect.

💡 If the bug is confirmed, would you be willing to create a pull request?

Yes

Is your issue with...

  • iOS
  • Android
  • Windows

Are you using...

  • React Native CLI (e.g. react-native run-android)
  • Expo
  • Other: (please specify)

Which versions are you using?

  • React Native Sound: "^0.11.0"
  • React Native: "~0.61.4"
  • iOS: 12.1.4
  • Android: 10
  • Windows: X

Does the problem occur on...

  • Simulator
  • Device

If your problem is happening on a device, which device?

  • Device: Iphone 7
@EyadAlghamdi
Copy link

i have the same issue. i tried every possible solution but it doesnt seem to duckOthers. this is not implemented yet it seems in the package.

@EyadAlghamdi
Copy link

I just created a new PR for this feature (only for iOS) #745
If there are any Android developers willing to add on to this fork that would be great!

if you want to test it out and provide any feedback just do

npm install https://github.com/EyadAlghamdi/react-native-sound

it will replace the main branch with the new branch to test it, later you can redo

npm install react-native-sound

and it will replace it back.

If you install the ducking branch. make sure you use the updated setCategory method which have a new parameters (3rd) named duckOthers

@param category  AVAudioSession category
@param mixWithOthers  Can be set to true to force mixing with other audio sessions.
@param duckOthers  Can be set to true to duck other sounds (iOS).

Sound.setCategory("Playback", true, true)

test it out and let me know if you face any issues so i can modify it :)
cheers!

@dipankurXT
Copy link

dipankurXT commented Apr 28, 2022

@EyadAlghamdi

npm install https://github.com/EyadAlghamdi/react-native-sound

Worked like a charm. Thanks a lot.

@arunabhverma
Copy link

Hi @EyadAlghamdi, I am using your repo it work for me good, but I need duck and unDuck feature for IOS and android both,
Now in my scenario, after ducking background sound it increases slowly slowly, and also not going to it original level of volume, and I am unable to fully unDuck the volume of background sound.

Can you help me in this scenario.

@adil-ali-dev
Copy link

Hi @EyadAlghamdi,after ducking background sound it increases slowly slowly, and also not going to it original level of volume, and I am unable to fully unDuck the volume of background sound

@lordprana
Copy link

Hello all, here's a patch file that incorporates @EyadAlghamdi changes + changes for Android. I've tested and it works on my devices.
react-native-sound+0.11.2.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants