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);
});