HTML 嵌入 autoplay="false",但仍自动播放
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20286541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML embed autoplay="false", but still plays automatically
提问by Steve
On the front page of this website, there is a sticky post titled "National Radio Advertising Campaign ForACURE" which contains the following HTML:
在这个网站的首页,有一个名为“全国广播广告运动 ForACURE”的置顶帖,其中包含以下 HTML:
<embed type="audio/x-wav" src="http://www.foracure.org.au/wp-content/uploads/FOR-A-CURE-RADIO-Daniel-45sec.mp3" autoplay="false" height="20" width="200" autostart="false">
However, when I load this website in Chrome v31.0.1650.57 m, the audio plays automatically, even though both autoplay and autostart are set to false.
但是,当我在 Chrome v31.0.1650.57 m 中加载此网站时,即使自动播放和自动启动都设置为 false,音频也会自动播放。
Is there a better cross browser method of embedding this audio?
是否有更好的跨浏览器嵌入此音频的方法?
采纳答案by Esteban R V
Chrome doesn't seem to understand true
and false
.
Use autostart="1"
and autostart="0"
instead.
Chrome 似乎不理解true
和false
. 使用autostart="1"
和autostart="0"
代替。
Source: (Google Groups: https://productforums.google.com/forum/#!topic/chrome/LkA8FoBoleU)
来源:(谷歌群组:https: //productforums.google.com/forum/#!topic/chrome/ LkA8FoBoleU)
回答by Jei
<video width="320" height="240" controls autoplay>
<source src="movie.mp4" type="video/mp4"> Your browser does not support the video tag.
</video>
Remove autoplay
if you want to disable auto playing video.
autoplay
如果要禁用自动播放视频,请删除。
回答by user2199629
Just set using JS as follows:
只需使用JS设置如下:
<script>
var vid = document.getElementById("myVideo");
vid.autoplay = false;
vid.load();
</script>
Set true
to turn on autoplay. Set false
to turn off autoplay.
设置true
为开启自动播放。设置false
为关闭自动播放。
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_av_prop_autoplay
http://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_av_prop_autoplay
回答by Babblo
Just change the mime type to: type="audio/mpeg"
, this way chrome will honor the autostart="false"
parameter.
只需将 mime 类型更改为: type="audio/mpeg"
,这样 chrome 就会遵守该autostart="false"
参数。
回答by Sumithran
This will prevent browser from auto playing audio.
这将阻止浏览器自动播放音频。
HTML
HTML
<audio type="audio/wav" id="audio" autoplay="false" autostart="false"></audio>
jQuery
jQuery
$('#audio').attr("src","path_to_audio.wav");
$('#audio').play();
回答by Cristina
the below codes helped me with the same problem. Let me know if it helped.
下面的代码帮助我解决了同样的问题。如果有帮助,请告诉我。
<!DOCTYPE html>
<html>
<body>
<audio controls>
<source src="YOUR AUDIO FILE" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</body>
</html>
回答by user5121219
The problem is your plugin. To solve this is to only enter this address:
问题是你的插件。要解决此问题,只需输入此地址:
chrome://flags/#enable-NPAPI
chrome://flags/#enable-NPAPI
Click activate NPAPI, and finally restart at the bottom of the page.
点击激活NPAPI,最后在页面底部重启。