Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

243
Vistas
React: Audio does not play

I want an audio to play on a click on a button. The audio has to be choosed based on the selected animal. The function providing the audio looks like this:

    function introAudioForAnimal(animal) {
        if (animal == "siri") { return }
        let audioImport = import("../assets/audio/wer_wars/" + animal + "/" + animal + " anfang.wav");
        return new Audio(audioImport);
    }

The returned audio is then just played by introAudioForAnimal("tiger").play();

The issue is, that nothing plays, but I get an uninformative console error:

index.js:1 Uncaught Error: The error you provided does not contain a stack trace.
    at L (index.js:1)
    at Y (index.js:1)
    at index.js:1
    at index.js:1
    at l (index.js:1)
L @ index.js:1
Y @ index.js:1
(anonymous) @ index.js:1
(anonymous) @ index.js:1
l @ index.js:1
game:1 Uncaught (in promise) DOMException: Failed to load because no supported source was found.

I have already tried logging the exact path:

../assets/audio/wer_wars/tiger/tiger anfang.wav

This matches my filesystem on where the audio is located.

Any ideas how I can get the audio to play? If you need any further information, please let me know.

Edit: My browser is google chrome, if that helps you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

For everyone else searching, I found a solution:

First of all I changed the way I defined the path:

let audioImport = import(`../assets/audio/wer_wars/${animal}/${animal} anfang.wav`);

And the key problem was, that you need to use the default property of that dynamic import to create a new audio:

new Audio(audioImport.default);

This solution did work for me very well.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda