Youtube Iframe禁用暂停视频
我需要在我的网页上播放视频。但我需要拒绝控制。 我把“控制=0”,但玩家有暂停行动,当我点击它。 我可以在YouTube播放器中禁用“暂停”操作吗?“?控制=0”仅隐藏播放器中的底部控制面板,但在单击屏幕时,播放/暂停将正常工作 以下是控制参数值:Youtube Iframe禁用暂停视频,iframe,youtube,youtube-api,Iframe,Youtube,Youtube Api,我需要在我的网页上播放视频。但我需要拒绝控制。 我把“控制=0”,但玩家有暂停行动,当我点击它。 我可以在YouTube播放器中禁用“暂停”操作吗?“?控制=0”仅隐藏播放器中的底部控制面板,但在单击屏幕时,播放/暂停将正常工作 以下是控制参数值: 控件=0–播放机控件不显示在播放机中。对于AS3 玩家,Flash播放器立即加载 controls=1–播放器控件显示在播放器中。对于AS3玩家, Flash播放器立即加载 controls=2–播放器控件显示在播放器中。对于AS3玩家, 用户启动
- 控件=0–播放机控件不显示在播放机中。对于AS3 玩家,Flash播放器立即加载
- controls=1–播放器控件显示在播放器中。对于AS3玩家, Flash播放器立即加载
- controls=2–播放器控件显示在播放器中。对于AS3玩家, 用户启动视频播放后,Flash播放器将加载
无法完全禁用暂停
您可以在处理程序中侦听
YT.PlayerState.PAUSED
事件,并在检测到事件时立即调用playVideo(),但是。。。我不知道,这听起来好像不太方便用户使用。您可以尝试在视频上放置一个div容器,上面什么都没有。换句话说,一个与视频本身大小相同的空白容器。这应该做的是,当有人试图点击它时,他们实际上会点击它上面的透明容器,并且不能暂停。这应该行得通。您还可能需要更改Z索引以确保空白DIV容器确实在视频上。(首先用背景色测试div容器,如果彩色框覆盖了视频,那么您可以返回并删除颜色,它也会工作。)祝您好运
另外,将
disablekb
参数设置为1,这样用户即使通过空格键也不能暂停。在DOM元素上使用以下CSS:
.ytplayer {pointer-events: none;}
这里有一种阻止屏幕的方法,这样用户就不能点击任何东西
// block screen so user cant click
var blockDiv = $(document.createElement('div'))
.attr('id', 'blockDiv')
.height('100%').width('100%')
.css({'z-index':'3333', 'position' : 'absolute', 'top': '0', 'left':'0'});
$('body').append(blockDiv);
如果您通过HTML显示视频,并且可以访问用于显示视频的CSS类,则可以执行以下操作 您的HTML将如下所示:
<iframe id="ytplayer" type="text/html" width="720" height="405"
src="https://www.youtube.com/watch?v=z4O-5eV4LiA"
frameborder="0" allowfullscreen>
下面是我的例子
<iframe class="ytplayer" id="ytplayer" type="text/html" width="720" height="405"
src="https://www.youtube.com/watch?v=z4O-5eV4LiA"
frameborder="0" allowfullscreen>
应该这样做 这是我的代码解决方案,可以让视频自动播放,而不需要在桌面上暂停,但允许在手机上播放
<style>
.overlay {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
/* knock out nasty borders */
outline: 2px solid white !important;
outline-offset: -1px;
pointer-events: none;
}
.wrapper-with-intrinsic-ratio {
position: relative;
padding-bottom: 56.25%;
}
.element-to-stretch iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #ffff;
}
.wrapper-with-intrinsic-ratio .element-to-stretch {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
@media only screen and (max-width: 900px) {
.noclick {
display: none;
}
}
.noclick {
z-index: 2000;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<div class="target2">
<div class="noclick"></div>
<div class="wrapper-with-intrinsic-ratio">
<div class="element-to-stretch">
<div class="overlay"><iframe title="YouTube video player" src="https://www.youtube.com/embed/tgbNymZ7vqY?rel=0&autoplay=1&controls=0&disablekb=1&loop=1&playlist=tgbNymZ7vqY&playsinline=1&iv_load_policy=3&mute=1&widgetid=1&widget_referrer" width="100%" height="100%" frameborder="0" allowfullscreen=""></iframe></div>
</div>
</div>
</div>
.覆盖{
位置:绝对位置;
排名:0;
底部:0;
右:0;
左:0;
/*打破肮脏的边界*/
轮廓:2件纯白!重要;
轮廓偏移:-1px;
指针事件:无;
}
.具有内在比率的包装器{
位置:相对位置;
垫底:56.25%;
}
.元素以拉伸iframe{
位置:绝对位置;
排名:0;
左:0;
宽度:100%;
身高:100%;
背景:#ffff;
}
.具有内在比率的包装器.元素到拉伸{
位置:绝对位置;
排名:0;
左:0;
宽度:100%;
身高:100%;
}
@仅介质屏幕和(最大宽度:900px){
诺克利克先生{
显示:无;
}
}
诺克利克先生{
z指数:2000;
位置:绝对位置;
排名:0;
左:0;
宽度:100%;
身高:100%;
}
注意:若要使视频重复且不自动播放播放列表上的下一项,请将播放列表设置为视频id(youtube)在浏览器视频中的移动设备上不执行视频建议是。这不是用户友好,但这不是我的愿望。无论如何,谢谢。这是否违反了YouTube的服务条款?真的不确定,可能违反了2b下的权限和限制限制限制了服务或内容的使用;好问题,api真的很差(我在两年后发布)
.ytplayer {
pointer-events: none;
position: absolute;
}
<style>
.overlay {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
/* knock out nasty borders */
outline: 2px solid white !important;
outline-offset: -1px;
pointer-events: none;
}
.wrapper-with-intrinsic-ratio {
position: relative;
padding-bottom: 56.25%;
}
.element-to-stretch iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #ffff;
}
.wrapper-with-intrinsic-ratio .element-to-stretch {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
@media only screen and (max-width: 900px) {
.noclick {
display: none;
}
}
.noclick {
z-index: 2000;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<div class="target2">
<div class="noclick"></div>
<div class="wrapper-with-intrinsic-ratio">
<div class="element-to-stretch">
<div class="overlay"><iframe title="YouTube video player" src="https://www.youtube.com/embed/tgbNymZ7vqY?rel=0&autoplay=1&controls=0&disablekb=1&loop=1&playlist=tgbNymZ7vqY&playsinline=1&iv_load_policy=3&mute=1&widgetid=1&widget_referrer" width="100%" height="100%" frameborder="0" allowfullscreen=""></iframe></div>
</div>
</div>
</div>