setSpeakerphoneOn doesn't work
:beetle: Description setSpeakerphoneOn doesn't work
I looked up documentation for setSpeakerphoneOn at https://github.com/zmxv/react-native-sound/wiki/API, where it states that you just need to pass a boolean value into it. What I'm trying to achieve is to have a toggle button for switching on and off setSpeakerphoneOn for voicemail files :beetle: What is the observed behavior? Doesn't seem to work
:beetle: What is the expected behavior? Expected to have a toggle button for switching on and off setSpeakerphoneOn for voicemail files
:beetle: Please post your code: Posting snippets of my code:
...
play = async () => {
if (this.sound) {
this.sound.play(this.playComplete)
this.setState({playState: 'playing'})
} else {
const { id, userCredential, contentUrl } = this.props
const voiceMailURL = `${contentUrl}/content/voicemail/get?msgId=${id}&token=${userCredential.access_token}`
this.sound = new Sound(voiceMailURL, '', (error) => {
if (error) {
Alert.alert('Notice', 'audio file error. (Error code : 1)')
this.setState({playState: 'paused'})
} else {
this.setState({playState: 'playing', duration: this.sound.getDuration()})
this.state.useEarPiece ? this.sound.setSpeakerphoneOn(true) : this.sound.setSpeakerphoneOn(true)
this.sound.play(this.playComplete)
}
})
}
}
playComplete = (success) => {
if (this.sound) {
if (success) {
} else {
Alert.alert('Notice', 'audio file error. (Error code : 2)')
}
this.setState({playState: 'paused', playSeconds: 0})
this.sound.setCurrentTime(0)
}
}
toggleUseEarPiece = () => {
this.setState({
useEarPiece: !this.state.useEarPiece
})
}
render () {
...
<View style={{flexDirection: 'row', justifyContent: 'center'}}>
{this.state.playState === 'playing' &&
<TouchableOpacity style={{marginHorizontal: 20}} onPress={this.pause}>
<Icon color='#000' name='ios-pause' size={20} type='ionicon' />
</TouchableOpacity>}
{this.state.playState === 'paused' &&
<TouchableOpacity style={{marginHorizontal: 20}} onPress={this.play}>
<Icon color='#000' name='md-play' size={20} type='ionicon' />
</TouchableOpacity>}
</View>
...
<TouchableOpacity onPress={this.toggleUseEarPiece}>{speaker}</TouchableOpacity>
}
:bulb: Does the problem have a test case?
:bulb: Possible solution
:bulb: Is there a workaround?
:bulb: If the bug is confirmed, would you be willing to create a pull request?
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:
- React Native:
- iOS:
- Android:
- Windows:
Does the problem occur on...
- [ ] Simulator
- [ ] Device
If your problem is happening on a device, which device?
- Device:
I just noticed the same thing testing on Android. On iOS, I previously used setPlaybackCategory to create a toggle, but that does not work on Android either.
I made sure to set the MODIFY_AUDIO_SETTINGS permission. When I press the speaker toggle, the sound does pause for a second, and the volume seems to change for a second-- but sound is playing both through the speaker and the earpiece either way.
@brianomchugh What library did you use to get setPlaybackCategory? I checked on react-native-sound there's no such method..
@pappricot Oops, I meant setCategory... the following works for me with iOS and [email protected] (old version). I am going to try an older version on Android to see if it does anything.
if (this.state.speaker) {
this.sound.setCategory("PlayAndRecord")
} else {
this.sound.setCategory("Playback")
}
@pappricot I just noticed in your code you have true for both values of the toggle:
this.state.useEarPiece ? this.sound.setSpeakerphoneOn(true) : this.sound.setSpeakerphoneOn(true)
@pappricot any update on this?
any updates? I can't change the speakers output of on android!