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

174
Vistas
How to play audio when rendering a component in react js

I have a react app and in that there's a component called AudioComponent. I want to play an audio when that component loads. My code for the AudioComponent is as follow.

import mp3 from './Hymn.mp3'
    
function AudioComponent() {

     const audio = new Audio(mp3)

     useEffect(() => {
        audio.play()
      }, [])
      
        return (
          <div className="pp">
            
      This is the Audio component

    <div >

    </div>
 
          </div>
        );
      }
      
      export default AudioComponent;

when running the app the following error shows in the console.

AudioComponent.jsx:41 Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.

I want to play the audio when ever the audio component is used without any user interactions. what might be the issue?

about 4 years ago · Juan Pablo Isaza
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