I’m trying to play an mp3 file. Here’s my file structure:
- app_name
- assets
- sounds
- alarm.mp3
Here’s my code (only included relevant portions):
import { BarCodeScanner, Permissions, Audio, Asset } from 'expo';
componentDidMount() {
this.playSound();
}
playSound = async () => {
await Expo.Audio.setIsEnabledAsync(true);
const sound = new Expo.Audio.Sound({
source: require('./assets/sounds/alarm.mp3')
});
await sound.loadAsync();
await sound.playAsync();
}
I’m getting an error saying:
Possible Unhandled Promise Rejection (id: 0): Error: Cannot load null source!
What am I doing wrong? Thanks!