3

When testing it through Expo app on phones and simulator, everything works perfectly. The problem is when I build the app and test it on an Android device or in iOS simulator, the sound doesn't play.

import { Audio } from 'expo-av';

const SomeComponent => () => {
  const [sound, setSound] = useState();

  const playSound = async () => {
    const { sound } = await Audio.Sound.createAsync(
      require('../../../assets/sounds/sound.mp3'),
      { shouldPlay: true }
    );
    setSound(sound);

    await sound.playAsync();
  };

  return <TouchableOpacity onPress={playSound} />
}

Versions:

"expo": "^40.0.0",
"expo-av": "~8.7.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",

Tried also unloading the sound after it's done and it still doesn't work:

await sound
      .playAsync()
      .then(async (playbackStatus) => {
        setTimeout(() => {
          sound.unloadAsync();
        }, playbackStatus.playableDurationMillis);
      })
      .catch((error) => {
        console.log(error);
      });
GrgaMrga
  • 460
  • 5
  • 13
  • 1
    Here's another dev with the exact same problem -- same package versions and everything. I get no sound on an iPhone 12 with iOS 14.4, but it plays fine on an iPhone 11 simulator with iOS 13.2.2. I'm using the same code too (copied exactly from expo-av docs). – Byofuel Feb 01 '21 at 02:35
  • Yes! I also saw many people have problems with that. I am currently ejecting from the expo because of this :( – GrgaMrga Feb 01 '21 at 12:09
  • 1
    Do you have silent mode enabled on your phone? if so try turning it off or pass `playsInSilentModeIOS: true` – Matt Aft Apr 24 '21 at 21:31
  • Tried both. Didn't play with `playsInSilentModeIOS: true` either – GrgaMrga Apr 25 '21 at 11:20
  • @GrgMrga Did you ever find a solution to this problem? I'm currently experiencing it and don't know what the solution is. The most confusing bit is that there isn't a lot of traction on posts about this problem, is it really that rare to try to play sounds with a react-native application? – JohnyClash Jun 06 '22 at 21:46
  • Haven't tried in a while. Will update if I do. – GrgaMrga Jun 13 '22 at 21:37

0 Answers0