Stop background sound if Sound id played from react native app

1.9k Views Asked by At

I have video player in my app, which is working fine. But there is one problem when I play the video , if there is another sound playing in the background , it keeps on playing. The ideal scenario should be that background sound should stop playing and when I pause video then background sound should start playing again. I don't know how to handle such scenarios. Any help would be appreciated

1

There are 1 best solutions below

0
On

On iOS you can use AVAudioSessionCategoryAmbient to set how should sounds mix. Here is the list for possible options. Here and Here are the methods for react-native-sound for how you can set.

Sound.setCategory(value, mixWithOthers)

value {string} Sets AVAudioSession category, which allows playing sound in background, stop sound playback when phone is locked, etc. Parameter options: "Ambient", "SoloAmbient", "Playback", "Record", "PlayAndRecord", "AudioProcessing", "MultiRoute".

Sound.setMode(value)

value {string} Sets AVAudioSession mode, which works in conjunction with the category to determine audio mixing behavior. Parameter options: "Default", "VoiceChat", "VideoChat", "GameChat", "VideoRecording", "Measurement", "MoviePlayback", "SpokenAudio".

This should be called in conjunction with Sound.setCategory.