YouTube 嵌入播放器无法在 Javascript 中运行

YouTube embed player not working in Javascript

几天后,通过 Javascript 嵌入 YouTube 视频的代码停止工作了。现在视频加载但无法播放(播放按钮不可点击),控制台中出现此错误:

Uncaught TypeError: a.g.mX is not a function
at O_ (https://www.youtube.com/yts/jsbin/player-en_US-vfl8LqiZp/base.js:3796:24)
at new P_ (https://www.youtube.com/yts/jsbin/player-en_US-vfl8LqiZp/base.js:3791:111)
at new c2 (https://www.youtube.com/yts/jsbin/player-en_US-vfl8LqiZp/base.js:3985:268)
at new i2 (https://www.youtube.com/yts/jsbin/player-en_US-vfl8LqiZp/base.js:4005:210)
at i2.create (https://www.youtube.com/yts/jsbin/player-en_US-vfl8LqiZp/base.js:6950:321)
at zh.<anonymous> (https://www.youtube.com/yts/jsbin/www-embed-player-vflxTxlSH/www-embed-player.js:428:269)
at zh.k.lb (https://www.youtube.com/yts/jsbin/www-embed-player-vflxTxlSH/www-embed-player.js:428:308)
at Dh (https://www.youtube.com/yts/jsbin/www-embed-player-vflxTxlSH/www-embed-player.js:426:143)
at zh.k.pa (https://www.youtube.com/yts/jsbin/www-embed-player-vflxTxlSH/www-embed-player.js:419:176)
at https://www.youtube.com/yts/jsbin/www-embed-player-vflxTxlSH/www-embed-player.js:461:420

JS代码如下:

document.getElementById('player').setAttribute("style","height:"+(window.innerHeight * 0.87)+"px;");
document.getElementById('youtube_frame').src="http://www.youtube.com/player_api";
    var player;
    function onYouTubePlayerAPIReady() {
            player = new YT.Player('player', {
              height: "100%",
              width: "100%",
              videoId: start_video,
              events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange
              }
            });
    }
    function onPlayerReady(event) {

            player_ref = event.target;
            event.target.playVideo();
        }

        // when video ends
        function onPlayerStateChange(event) {        
            if(event.data === 0) {          

                event.target.loadVideoById(start_video);
            }
        }

Playback 也打破了我 运行 的另一个原型。直到几天前,一切都可以正常工作。我在网上找不到任何东西,也许有人可以解释一下?

----- 更新 ----

嵌入播放再次中断:

Uncaught TypeError: a.g.setActionHandler is not a function
at M_ (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:3788:24)
at new N_ (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:3783:111)
at new a2 (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:3978:367)
at new g2 (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:3999:210)
at g2.create (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:6995:333)
at Gi.<anonymous> (https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:507:269)
at Gi.l.jb (https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:507:308)
at Ki (https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:505:143)
at Gi.l.oa (https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:498:176)
at https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:557:378

问题已被 Google 解决,现在 YouTube 视频播放正常!

想知道发生了什么事吗?

----- 2017 年 2 月 23 日更新 ------

嵌入播放再次中断:

Uncaught TypeError: a.g.setActionHandler is not a function
at M_ (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:3788:24)
at new N_ (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:3783:111)
at new a2 (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:3978:367)
at new g2 (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:3999:210)
at g2.create (https://www.youtube.com/yts/jsbin/player-en_US-vflqOi6vK/base.js:6995:333)
at Gi.<anonymous> (https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:507:269)
at Gi.l.jb (https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:507:308)
at Ki (https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:505:143)
at Gi.l.oa (https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:498:176)
at https://www.youtube.com/yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:557:378

无论当前的问题是什么,它都与尝试附加事件时的 MediaSession 对象有关(在本例中为 play)。这个对象是 Chrome 的内部对象,所以似乎那里有东西损坏了。

我在使用 YouTube 的任何其他网站上都看到了同样的问题 - 所以不要浪费时间尝试调试您自己的网站。不是这个问题。

我已经重新启动并尝试禁用所有扩展。尚未看到任何修复。

主要是想 post 这样人们就不会浪费时间认为他们的代码不好。

我在 Chrome 56.0.2924.87(64 位)启用 "experimental functions" 时遇到这个问题。

base.js:7046 Uncaught TypeError: a.g.setActionHandler is not a function
at bY (https://www.youtube.com/yts/jsbin/player-ru_RU-vfleBND20/base.js:3618:24)
at new cY (https://www.youtube.com/yts/jsbin/player-ru_RU-vfleBND20/base.js:3613:111)
at new z1 (https://www.youtube.com/yts/jsbin/player-ru_RU-vfleBND20/base.js:3983:268)
at new j2 (https://www.youtube.com/yts/jsbin/player-ru_RU-vfleBND20/base.js:4044:209)
at Object.j2.create (https://www.youtube.com/yts/jsbin/player-ru_RU-vfleBND20/base.js:7045:317)
at Object.ytplayer.load (https://www.youtube.com/watch?v=n-AdoTkXwbc:241:75024)
at https://www.youtube.com/watch?v=n-AdoTkXwbc:241:75172
at https://www.youtube.com/watch?v=n-AdoTkXwbc:241:75181

我们可以在此处禁用此选项:chrome://flags/#enable-experimental-web-platform-features

-- 更新 10.03.2017 --

Chrome 57.0.2987.98(64 位)今天发布,工作正常