0

I am trying the example from https://docs.expo.dev/versions/latest/sdk/audio/#usage (I just replaced the path of the mp3 file) but my iPhone doesn't play the audio.

Basically, I copied this part (and added the necessary imports):

  const [sound, setSound] = useState();

  async function playSound() {
    console.log('Loading Sound');
    const { sound } = await Audio.Sound.createAsync(
      require('./path/to/my/file.mp3'));
    setSound(sound);

    console.log('Playing Sound');
    await sound.playAsync();
  }

  useEffect(() => {
    return sound
      ? () => {
          console.log('Unloading Sound');
          sound.unloadAsync();
        }
      : undefined;
  }, [sound]);

It doesn't crash, I just see these logs but hear no sound:

 LOG  Loading Sound
 LOG  Playing Sound

Does anyone know how to use it properly?

I checked this similar issue, but the solution doesn't work, and the versions are older: Expo-AV Sound.playAsync() doesn't work with expo-av 9.2.3 and Expo 42.0.3

These are the dependencies that might be relevant:

    "@react-navigation/native": "^6.1.7",
    "@react-navigation/native-stack": "^6.9.13",
    "expo": "~48.0.18",
    "expo-av": "~13.2.1",
    "react": "18.2.0",
    "react-native": "0.71.8",
Ferran Maylinch
  • 10,919
  • 16
  • 85
  • 100

1 Answers1

0

Ok, the solution was silly, but at the same somewhat tricky.

It turns out that I had my iPhone in silent mode, that is, with that red switch on the left.

The tricky thing is that I always have my iPhone in silent mode, but anyway I am able to listen to audios on the browser, YouTube, Whatsapp and so on. It looks like these apps bypass the silent mode. But other apps do not, e.g. expo.

Even more strange, I am able to play audios in expo, in silent mode, if it's through a Bluetooth speaker. So my Bluetooth speaker (or the Bluetooth system) also bypasses the silent mode.

I will not mark my answer, I will leave the question open, waiting for someone who can explain this a bit better. Maybe someone can explain how the silent mode actually works (especially in relation to expo, since this is the topic of the question).

Ferran Maylinch
  • 10,919
  • 16
  • 85
  • 100