Stop audio buffering in the <audio> tag

前端 未结 3 1571
我寻月下人不归
我寻月下人不归 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: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.

提交回复
热议问题