Stop audio buffering in the <audio> tag

前端 未结 3 1556
我寻月下人不归
我寻月下人不归 2021-02-18 23:24

I am currently working in using the HTML5 audio player to provide a audio stream (24/7 radio stream) via the (mobile) browser. Loading in the stream and playing it works fine. <

相关标签:
3条回答
  • 2021-02-19 00:02

    I found a workable solution for the problem described above. A detail description can be found here: https://stackoverflow.com/a/13302599/1580615

    0 讨论(0)
  • 2021-02-19 00:03

    You can do the following to stop buffering load without errors:

    var blob = new Blob([], {type: "audio/mp3"});
    var url = URL.createObjectURL(blob);
    audio.src = _url;
    

    or, shortened up:

    audio.src = URL.createObjectURL(new Blob([], {type:"audio/mp3"});
    

    Now you're not loading a "" which is a bad url for the audio tag to try and load. You're instead loading an actual url made from a Blob that just contains no data for the audio to playback.

    0 讨论(0)
  • 2021-02-19 00:27

    The <audio> element includes a preload attribute. This can be set to "none" or "metadata" which should prevent the audio preloading.

    Source: https://developer.mozilla.org/en/docs/Web/HTML/Element/audio

    0 讨论(0)
提交回复
热议问题