Please provide the following:
- SDK Version: 40
- Platforms(Android/iOS/web/all): all
- Add the appropriate “Tag” based on what Expo library you have a question on.
I’m using the sample expo-av code from this page to play sound files: Audio - Expo Documentation
It works fine when I hard-code a filename like this:
const { sound } = await Audio.Sound.createAsync(
require('./assets/Hello.mp3')
);
But the call to require will not accept variables as arguments – it wants a fixed filename only, so this fails:
const { sound } = await Audio.Sound.createAsync(
const filename = `./assets/${variable}.mp3`
require(filename)
);
The error is some variation of: Invalid call at line 50: require(filename)
My app is testing players with flashcards and has hundreds of sounds to choose from, so the filepaths need to be calculated. It appears the expo-av library has different ways of creating a sound object, but all involve the Asset class, and all the docs I’ve found so far only show using Asset with ‘require’ – I haven’t found any explanation of how to feed it a generated filepath.