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

286
Views
Recupere el archivo mp3 del caché y reprodúzcalo en el navegador

Tengo un archivo mp3 que estoy almacenando en caché como tal:

 const request = URL_TO_MY_MP3_FILE caches.open("my-cache").then(cache => { cache.add(request); });

Puedo ver que el archivo mp3 se almacena en caché en la pestaña Aplicación: ingrese la descripción de la imagen aquí

Por cierto, ¿cómo me aseguro de que el tipo de contenido se almacene en caché como audio/mp3 y no como audio/mpeg ?

Más adelante, me gustaría recuperar el archivo mp3 del caché para poder reproducirlo en el navegador:

 caches.open("my-cache").then(cache => { const responsePromise = cache.match(request); responsePromise.then(result => { console.log(result.body) this.audio = new Audio(result.body); const playPromise = this.audio.play(); playPromise.then(function() { console.log('success!') }).catch(function(error) { console.log(error) }.bind(this), false); });

})

Esta es la salida de console.log(result.body) : ingrese la descripción de la imagen aquí

Después de cargar el archivo mp3 con new Audio(result.body) , intento reproducir el archivo con this.audio.play() pero esto da como resultado un error:

DOMException: no se pudo cargar porque no se encontró una fuente compatible.

¿Cómo puedo recuperar el archivo mp3 del caché y reproducirlo en el navegador?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Tienes que llamar a reader.read()

 caches.open("my-cache").then(cache => { const responsePromise = cache.match(request); responsePromise.then(result => { var reader = result.body.getReader(); reader.read().then((result) => { const mimeType = 'audio/mpeg' const url = URL.createObjectURL(new Blob([result.value.buffer], {type: mimeType})) this.audio = new Audio(url); const playPromise = this.audio.play(); playPromise.then(function() { console.log('success!') }).catch(function(error) { console.log(error) }.bind(this), false); }); });

});

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!