Cannot play sound in expo project using expo-av

35 views Asked by At
import {Audio} from 'expo-av';

  useEffect(() => 
    const enableAudio = async () => {
    await Audio.setAudioModeAsync({
      playsInSilentModeIOS: true,
      staysActiveInBackground: false,
      // interruptionModeAndroid: INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
      shouldDuckAndroid: false,
    });
  };
    enableAudio();
    playSound();
  }, []);

  const enableAudio = async () => {
    await Audio.setAudioModeAsync({
      playsInSilentModeIOS: true,
      staysActiveInBackground: false,
      // interruptionModeAndroid: INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
      shouldDuckAndroid: false,
    });
  };

  const playSound = () => {
    try {
      const { sound: s } = await Audio.Sound.createAsync(
        require('../../assets/sounds/strongClick.wav'),
      );
      setSound(s);
      await s.playAsync();
    } catch (err) {
      console.log(err);
    }
  };

No sound. What am i doing wrong?

1

There are 1 answers

0
Adrian Bartholomew On

My bad. I didn't have the volume up on the simulator. For those having the same problem, just click the left side button on the simulator near the top and drag up.