Pre-loaded sounds being unloaded?

天大地大妈咪最大 提交于 2019-12-01 12:46:43

You can fetch all your medias as Blobs, and then create blobURIs from it.

This way, the browser will keep it in memory (until an hard refresh or until you call URL.revokeObjectURL(blobURI);)

fetch("https://dl.dropboxusercontent.com/s/8c9m92u1euqnkaz/GershwinWhiteman-RhapsodyInBluePart1.mp3")
.then(r => r.blob()) // could be xhr.responseType = 'blob'
.then(blob => {
  const aud = new Audio(URL.createObjectURL(blob));
  aud.controls = true;
  document.body.appendChild(aud);
  console.log('Fully loaded and cached until the page dies...')
  });

Have a look at Service Workers.

OLD ANSWER:

Otherwise, did you take a look at localStorage?

Also, check out this blog post about how to store binary data in localStorage.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!