On Play: Make Youtube Video Full Screen

夙愿已清 提交于 2019-12-12 10:54:40

问题


Using the Youtube Javascript API; is there a way to make the video play full screen when the 'Play' button is clicked?

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.

If there isn't any way to do this through the Youtube Javascript API, do you know of a Cross Browser way I could make the youtube video full screen when play is clicked?

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>

回答1:


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



来源:https://stackoverflow.com/questions/17286787/on-play-make-youtube-video-full-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!