zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

How to play sound through earpiece speaker on iOS devices? #622

Open jordibruin opened 4 years ago

jordibruin commented 4 years ago

:beetle: Description I'm trying to play a sound through the earpiece speakers so that a user can only hear it when they put the phone up to their ear.

:beetle: What have you tried? It seems like this feature is only implemented for android, by using the playThroughEarpieceAndroid: true prop.

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

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

:beetle: Please post your code:


Audio.setAudioModeAsync({
      allowsRecordingIOS: false,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
      playsInSilentModeIOS: true,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
      playThroughEarpieceAndroid: true,
      staysActiveInBackground: false
    });
  }

  async _playRecording() {
    const { sound } = await Audio.Sound.create(
      source,
      {
        shouldPlay: true,
        isLooping: true
      },
      this._updateScreenForSoundStatus
    );
    this.sound = sound;
    this.setState({
      playingStatus: "playing"
    });
  }