在游戏中:制作Youtube视频全屏 [英] On Play: Make Youtube Video Full Screen
问题描述
使用Youtube Javascript API; 是否可以在点击播放按钮时全屏播放视频?
Using the Youtube Javascript API; is there a way to make the video play full screen when the 'Play' button is clicked?
我知道一种制作方法视频容器全屏但这仅适用于最新版本Firefox和Chrome版本。
I am aware of a way to make the video container full screen but this only works for the latest versions of Firefox and Chrome.
如果没有办法通过Youtube Javascript API执行此操作,您是否知道我可以使用跨浏览器方式单击播放时将YouTube视频全屏显示?
这是在点击最新版本的Firefox并点击播放时全屏播放视频的方式Chrome浏览器:
This is how you make a video full screen when play is clicked for the latest versions of Firefox and Chrome browsers:
function onPlayerStateChange(event) {
var player = document.getElementById("MSJbUEj7U7M");
if (event.data != YT.PlayerState.BUFFERING && event.data != YT.PlayerState.CUED && event.data != YT.PlayerState.PLAYING)
return -1;
if (player.requestFullScreen) {
console.log("1()");
player.requestFullScreen();
}
else if (player.mozRequestFullScreen) {
console.log("2()");
player.mozRequestFullScreen();
}
else if (player.webkitRequestFullScreen) {
console.log("3()");
player.webkitRequestFullScreen();
}
}
function loadYouTubeVideo(uid) {
setTimeout( function() {
var id = uid;
var instPlayer = new YT.Player(id, {
height: '480',
width: '853',
enablejsapi: 1,
suggestedQuality: 'highres',
videoId: uid,
events: {
'onStateChange': onPlayerStateChange
}
});
}, 500);
}
</script>
推荐答案
看起来你不能这样做,除非用户点击全屏。
It looks like you can't do this unless the user clicks full screen.
https://groups.google.com/forum/#!msg/youtube-api-gdata/Tyv3vTw0RQk/449KahYVNFYJ
这篇关于在游戏中:制作Youtube视频全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!