Sound, dynamic path

#1

In my child component which receive sound and duration as props i want to access dynamically to the mp3 it doesn’t work…
If i try to access a sound statically it works.

playMusic = async () => {
    const { duration, sound } = this.props;
    // const mp3 = require(`../sounds/${duration}/${sound}.mp3`);
    const mp3 = require(`../sounds/galway-girl.mp3`);

    try {
      const audio = new Audio.Sound();
      await audio.loadAsync(mp3);
      await audio.playAsync();
    } catch (error) {
      console.error("music", mp3);
    }
  };

Any idea ? :slight_smile:

#2

We have to have a static path to be able to bundle all of your app’s assets together for upload to our servers. At the moment you can make your own “registry” of local paths that will resolve the duration and sound props to a specific filename that’s referenced elsewhere.

#3

I already have a json file where i store path. Is it what your meaning ?

[{
title: "My sound 1",
sound: "mySound1.mp3",
duration: "short"
}, {
title: "My sound 2",
 sound: "mySound2.mp3",
duration: "long"
}]

The final goal is just a soundbox ^^
The parent component only map the child.

#4

Yeah, I think you’ll want to make this a JavaScript file that requires these files itself, and then exports the require’d modules.