附带的问题:Make youtube video fullscreen using iframe and javascript API
我有一个补充问题:
'Alkindus'的codepen代码非常感谢!
(我以“ height:0;”隐藏了视频,并将其链接到网址)
在逃脱时,视频隐藏了,但继续播放, 而且我找不到如何在“转义”上观看视频
尝试了以下内容:
window.addEventListener("keydown", function (event) {
if (event.defaultPrevented) {
return; // Do nothing if the event was already processed
}
if(event.key === "Escape") {
//alert('escape');
player.stopVideo();
}
event.preventDefault();
}, true);
它触发了我的逃生,但是在视频中,我必须双击“逃生”
也许是全屏状态更改后触发的某些事件监听器?或某种回调。任何人都知道我需要朝哪个方向搜索?
答案 0 :(得分:0)
解决方案: YouTube Player API detect fullscreen exit
document.addEventListener("fullscreenchange", function() {
if (!document.fullscreenElement) player.stopVideo();
}, false);
document.addEventListener("msfullscreenchange", function() {
if (!document.msFullscreenElement) player.stopVideo();
}, false);
document.addEventListener("mozfullscreenchange", function() {
if (!document.mozFullScreen) player.stopVideo();
}, false);
document.addEventListener("webkitfullscreenchange", function() {
if (!document.webkitIsFullScreen) player.stopVideo();
}, false);