如何防止在 iframe html 中自动播放?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22748681/
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
how to prevent autoplay in iframe html?
提问by user3259990
I have used iframe with video autoplay stop. But it always in autoplay mode. I do not want to autoplay. I want to stop autoplay.
我使用了带有视频自动播放停止功能的 iframe。但它始终处于自动播放模式。我不想自动播放。我想停止自动播放。
there is my code below
下面是我的代码
<iframe width="245" height="190" frameborder="0"
src="Pacers_VS_Lakers_with_LifeWave_Energy_Patches.mp4?autoplay=0&cc_load_policy=1">
</iframe>
回答by Kaif Khan
Just use video
tag instead of iframe
.
只需使用video
tag 而不是iframe
.
<video height="100" width="100">
<source src="some_video_url">
</video>
It will not autoplay itself. Its actually a better option instead of iframe tag.
它不会自动播放。它实际上是一个更好的选择,而不是 iframe 标签。
回答by N'Bayramberdiyev
Once, I had the same problem. I tried the following options:
有一次,我遇到了同样的问题。我尝试了以下选项:
<iframe width="245" height="190" src="filename.mp4?autoplay=0"></iframe>
<iframe width="245" height="190" src="filename.mp4?autoplay=false"></iframe>
<iframe width="245" height="190" src="filename.mp4?autostart=0"></iframe>
<iframe width="245" height="190" src="filename.mp4?autostart=false"></iframe>
<iframe width="245" height="190" src="filename.mp4?rel=0"></iframe>
<iframe width="245" height="190" src="filename.mp4?rel=0&cc_load_policy=1"></iframe>
<iframe width="245" height="190" src="filename.mp4?autoplay=0"></iframe>
<iframe width="245" height="190" src="filename.mp4?autoplay=false"></iframe>
<iframe width="245" height="190" src="filename.mp4?autostart=0"></iframe>
<iframe width="245" height="190" src="filename.mp4?autostart=false"></iframe>
<iframe width="245" height="190" src="filename.mp4?rel=0"></iframe>
<iframe width="245" height="190" src="filename.mp4?rel=0&cc_load_policy=1"></iframe>
But it never worked. Using<video>
tag solved my issue:
但它从来没有奏效。使用<video>
标签解决了我的问题:
<video width="245" height="190" controls><source src="filename.mp4" type="video/mp4"></video>
<video width="245" height="190" controls><source src="filename.mp4" type="video/mp4"></video>
回答by Kay777
I believe your best bet may be to link a play button to the $("iframe").attr("src""abc.mp4") command and start your iframe with an img src instead. I don't think autoplay can be turned off, at least w/ mp4's. So start with a static src and then use jQuery to change the src attribute to your video upon clicking a button/element; you can repeat this and have a bunch of different elements trigger their own videos.
我相信您最好的选择可能是将播放按钮链接到 $("iframe").attr("src""abc.mp4") 命令,然后使用 img src 启动 iframe。我认为不能关闭自动播放,至少可以关闭 mp4。因此,从静态 src 开始,然后在单击按钮/元素时使用 jQuery 将 src 属性更改为您的视频;你可以重复这个,让一堆不同的元素触发他们自己的视频。
回答by Venom
Did you try with the parameter autoplay=false instead of autoplay=0 ?
您是否尝试使用参数 autoplay=false 而不是 autoplay=0 ?
回答by priyanka kotnala
<iframe src="Pacers_VS_Lakers_with_LifeWave_Energy_Patches.mp4?rel=0&cc_load_policy=1">
回答by Farzad
Add this :
autoplay=false
添加这个:
autoplay=false
it should be solved.
应该解决。
回答by Genaf Latheef
I have tried lots of methods but none have worked for me.
我尝试了很多方法,但没有一个对我有用。
Finally I found the reason.
最后我找到了原因。
I am using:
我在用:
<iframe width="350" height="229.69" src="images/001.mp4"></iframe>
tag, thats why autoplay is not stopping.
标签,这就是为什么自动播放不会停止。
Use <video> </video>
tag it will work add "Control in video tag"
使用<video> </video>
标签它将工作添加“控制视频标签”
回答by Daniel
Here you have to use the video tag to stop autoplay but for responsive use the embed-responsive
class from Bootstrap4.
在这里,您必须使用 video 标签来停止自动播放,但为了响应,请使用embed-responsive
Bootstrap4 中的类。
<div class="embed-responsive embed-responsive-16by9 hoverable">
<video class="embed-responsive-item" controls>
<source src="assets/Video/yourvideoname.mp4" type="video/mp4">
</video>
</div>