zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 749 forks source link

Please explain how make sound from ear speaker. #688

Closed KZinc closed 4 years ago

KZinc commented 4 years ago

:beetle: Description

I want sound not from main speaker, but from ear one. :beetle: What have you tried? I've tried Sound.setCategory('Playback'); With all of the categories, Alarm makes sound twice quite but still not from speakerphone i want.

There is closed request which says I should use Sound.setCategory('Playback'); :beetle: Please post your code: import Sound from 'react-native-sound'; Sound.setCategory('Playback');


const [voice] = useState( new Sound(message, () => { if (!timeout) { setTimeoutValue(setInterval(() => { voice.getCurrentTime((pos) => { setCounter(Math.floor((voice.getDuration() - pos) * 10)); }); }, 500)); } }), );


const play = (): void => { voice.play(() => voice.release()); };


// Please post your code

:bulb: Possible solution

Is your issue with...

Which versions are you using?

Does the problem occur on...

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

KZinc commented 4 years ago

I found that if I use 'Voice' I got needed result.

anniewey commented 2 years ago

@KZinc can you share your code? i'm facing same issue.

KnowYourLines commented 1 year ago

Sound.setCategory('Voice'); is what does the trick. It is not documented anywhere but it worked for me.

I believe it works because of https://github.com/zmxv/react-native-sound/blob/1aa45f25c8c03ea5c17fac18564c3928bd023113/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java#LL88C1-L88C1 for Android while for iOS the default is to play through the ear speaker.