Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Cómo reproducir audio al renderizar un componente en reaccionar js

Tengo una aplicación de reacción y hay un componente llamado AudioComponent . Quiero reproducir un audio cuando se carga ese componente. Mi código para AudioComponent es el siguiente.

 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;

al ejecutar la aplicación, aparece el siguiente error en la consola.

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

Quiero reproducir el audio siempre que se use el componente de audio sin ninguna interacción del usuario. ¿Cuál podría ser el problema?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!