React Native: 0.54.4
React Native Sound: 0.10.9
Tested Devices: iPhone 4, iPhone 6, iPhone 8
Tested File Types: mp3, m4a
When playing an audio file (mp3 or m4a) I hear no sound. But when I plug headphones I can now hear the audio that is playing. This problem does not exist on the simulator and only showed up after testing on actual hardware.
Has this issue occurred to anyone else? I'm not sure what steps to take for debugging from here.
componentWillMount() {
this.audio = new Sound(this.props.url, null, (error) => {
if (error) {
Alert.alert("Error", error.message);
}
this.setState({
timeListened: 0,
timeRemaining: this.audio.getDuration(),
audioDuration: this.audio.getDuration(),
isReady: true
});
if (this.props.onLoad) this.props.onLoad();
});
}
componentWillUnmount() {
if (this.audio) this.audio.release();
this.cancelTimingInterval();
}
play = () => {
this.setState({isPlaying: true});
this.timingInterval = setInterval(this.onTimeChange, 250);
this.audio.play(this.onAudioComplete);
};
pause = () => {
this.audio.pause();
this.setState({isPlaying: false});
this.cancelTimingInterval();
};
cancelTimingInterval = () => {
if (this.timingInterval) clearInterval(this.timingInterval);
};
This part of the documentation fixed the issue. I have no idea why though.
// Enable playback in silence mode
Sound.setCategory('Playback');
Most helpful comment
This part of the documentation fixed the issue. I have no idea why though.