如何防止 HTML5 音频在加载时预下载/流式传输? [英] How to prevent HTML5 audio from predownload / streaming on load?
问题描述
我有一个单页网站,其中列出了 HTML5 音频播放器的集合.问题是网站变慢了,因为以下浏览器开始预下载内容(mp3 和 ogg)
I have a single page website which lists a collection of HTML5 audio players. The problem is the site has become slow because the following browsers start predownloading the content (mp3 and ogg)
Internet Explorer
Google Chrome
Firefox
Safari
(probably Opera)
我使用基本代码来实现播放器.有什么办法可以防止浏览器预先下载音频文件,并且仅在它们点击播放时才起作用?
I use the basic code to implement the players. Is there a way I can prevent the browsers from predownloading the audio files and only work when they click play?
<audio controls="controls" height="32" width="300" tabindex="0">
<source type="audio/mpeg" src="http://cdn.com/track.mp3"></source>
<source type="audio/ogg" src="http://cdn.com/track.ogg"></source>
</audio>
推荐答案
<audio controls="controls" preload="none">
<source src="song.ogg" type="audio/ogg" />
<source src="song.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
注意 - preload="none"
- 可用于视频 HTML5 和音频 HTML5.
Note - preload="none"
- can be used with VIDEO HTML5 and AUDIO HTML5.
除 Internet Explorer 和 Opera 外,所有主流浏览器都支持 preload 属性.
The preload attribute is supported in all major browsers, except Internet Explorer and Opera.
这篇关于如何防止 HTML5 音频在加载时预下载/流式传输?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!