HTML5 Local Storage of audio element source - is it possible?

后端 未结 6 1639
不思量自难忘°
不思量自难忘° 2020-11-30 22:35

I\'ve been experimenting with the audio and local storage features of html5 of late and have run into something that has me stumped.

I\'d like to be able to cache or

6条回答
  •  感动是毒
    2020-11-30 23:02

    I spent a while trying to do this for a game I'm making, and since as far as I could tell browsers (Firefox and Chrome) still don't support caching of audio elements I thought I'd post the solution I found.

    There is a workaround described here: http://dougx.net/plunder/index.php#code

    I can confirm it works pretty well, but is probably better suited to smaller files. As he describes here (http://dougx.net/plunder/GameSounds.txt), you encode the audio as base64 strings, and give them a data:audio/ogg;base64 (or any compatible audio format) header, which HTML5 audio can then read in. Because this is just a string, the browser will cache it.

提交回复
热议问题