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

355
Vistas
How to play audio file with vue.js

I'm trying to play an audio file in my vue.js project as such:

import sound from '../../recordings/sound.mp4'
const audio = new Audio(sound) 
audio.play()

This works perfectly well, but import may only appear at the top level - not within a function that would ideally accept any audio file.

Now I tried doing it this way:

const audio = new Audio('../../recordings/sound.mp4') 
audio.play()

But then I get this error:

DOMException: Failed to load because no supported source was found

I found a solution to this strange error in this answer: DOMException: Failed to load because no supported source was found

The solution was to use the import statement - but the issue is the the import statement can only be used at the top level - not within a function.

So how can I dynamically play an audio file with vue.js?

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

0

You can import your audio file inside a function using Dynamic Imports

(async () => {
  let sound = await import('../../recordings/sound.mp4');
  const audio = new Audio(sound);
  audio.play();
})();
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