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

343
Views
¿Cómo grabar audio y video usando JAVASCRIPT? (REACCIONAR JS)

Lo he intentado pero hay un error "Error de tipo: no se pueden leer las propiedades de undefined (leyendo 'detener')" Estoy llamando a la función en el botón, haga clic aquí también es una función :)

 const getAudio= async ()=>{ let device = await navigator.mediaDevices.getUserMedia({audio: true}); let chunks = []; let recorder; device.then(stream => { recorder = new MediaRecorder(stream); recorder.ondataavailable = e => { chunks.push(e.data); if (recorder.state === 'inactive') { this.blob = new Blob(chunks, {type: 'audio/webm'}); let testAudioRecord = URL.createObjectURL(this.blob); console.log(testAudioRecord) } } recorder.start(1000); }); setTimeout(() => { recorder.stop(); // Cannot read ('stop') =error }, 2000) }
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Veo un poco de confusión entre el uso de async con await y el manejo de .then promise.

Dado que está utilizando una función asíncrona, refactoricemos para try...catch con await para esperar a que se resuelva la promoción.

 const getAudio = async () => { let chunks = []; let recorder; try { //wait for the stream promise to resolve let stream = await navigator.mediaDevices.getUserMedia({ audio: true }); recorder = new MediaRecorder(stream); recorder.ondataavailable = (e) => { chunks.push(e.data); if (recorder.state === "inactive") { this.blob = new Blob(chunks, { type: "audio/webm" }); let testAudioRecord = URL.createObjectURL(this.blob); console.log(testAudioRecord); } }; recorder.start(1000); setTimeout(() => { recorder.stop(); }, 2000); } catch (e) { console.log("error getting stream", e); } };

Hay mejores formas de construir el código, pero esto debería hacer que su función funcione.

Aquí hay un codesandbox con su función y una opción de reproducción.

Aquí hay otro audio codesandbox

about 4 years ago · Santiago Gelvez Report
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!