React-native-sound: [iPhone] - Audio plays with headphones, but not speakers

Created on 19 Jun 2018  路  1Comment  路  Source: zmxv/react-native-sound

Versions and Devices

React Native: 0.54.4
React Native Sound: 0.10.9
Tested Devices: iPhone 4, iPhone 6, iPhone 8
Tested File Types: mp3, m4a

Description

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.

Relevant Code

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);
};

Most helpful comment

This part of the documentation fixed the issue. I have no idea why though.

// Enable playback in silence mode
Sound.setCategory('Playback');

>All comments

This part of the documentation fixed the issue. I have no idea why though.

// Enable playback in silence mode
Sound.setCategory('Playback');
Was this page helpful?
0 / 5 - 0 ratings

Related issues

VladimirJarabica picture VladimirJarabica  路  3Comments

gastonmorixe picture gastonmorixe  路  4Comments

therealproblem picture therealproblem  路  5Comments

viperfx picture viperfx  路  4Comments

jacargentina picture jacargentina  路  4Comments