PlayThroughEarpieceAndroid stops after some time and plays sound through Speaker

35 Views Asked by At

I am trying to build an audioplayer where the sound comes strictly out of the earpiece. It works for some seconds, but after some time or after replaying the audio, the sounds output changes to the speaker.

I Am using an Expo managed React Naitve app.

This is my code:

const loadAudio = async () => {
    try {
        await Audio.setAudioModeAsync({
          playsInSilentModeIOS: true,
          allowsRecordingIOS: true,
          interruptionModeIOS: InterruptionModeIOS.DoNotMix,
          shouldDuckAndroid: false,
          interruptionModeAndroid: InterruptionModeAndroid.DoNotMix,
          staysActiveInBackground: false,
          playThroughEarpieceAndroid: true,
        });
    
        const { sound, status } = await Audio.Sound.createAsync(
          {
            uri: audioguide_source,
          }
        );
    
        setSound(sound);
        setAudioLoading(false);
      } catch (error) {
        console.error("Error loading audio:", error);
        setAudioLoading(false);
      }
    }

Can someone please help me?

I tried to call Audio.setAudioModeAsync before and after playing the sound. No difference.

0

There are 0 best solutions below