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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:16:57  来源:igfitidea点击:

HTML embed autoplay="false", but still plays automatically

htmlaudio

提问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 trueand false. Use autostart="1"and autostart="0"instead.

Chrome 似乎不理解truefalse. 使用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 autoplayif 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 trueto turn on autoplay. Set falseto 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,最后在页面底部重启。