最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

YouTube embed player not working in Javascript - Stack Overflow

programmeradmin4浏览0评论

Since a couple of days, code which worked fine to embed a YouTube video via Javascript stopped working. Now the video loads but it is not playable (the play button is not clickable), with this error in the console:

Uncaught TypeError: a.g.mX is not a function
at O_ (.js:3796:24)
at new P_ (.js:3791:111)
at new c2 (.js:3985:268)
at new i2 (.js:4005:210)
at i2.create (.js:6950:321)
at zh.<anonymous> (.js:428:269)
at zh.k.lb (.js:428:308)
at Dh (.js:426:143)
at zh.k.pa (.js:419:176)
at .js:461:420

The JS code is as follows:

document.getElementById('player').setAttribute("style","height:"+(window.innerHeight * 0.87)+"px;");
document.getElementById('youtube_frame').src="";
    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 also broke on another prototype that I run. Everything used to work fine until a couple of days ago. I cannot find anything online, perhaps someone can shed some light?

----- UPDATE ----

Embedding playback is broken again:

Uncaught TypeError: a.g.setActionHandler is not a function
at M_ (.js:3788:24)
at new N_ (.js:3783:111)
at new a2 (.js:3978:367)
at new g2 (.js:3999:210)
at g2.create (.js:6995:333)
at Gi.<anonymous> (.js:507:269)
at Gi.l.jb (.js:507:308)
at Ki (.js:505:143)
at Gi.l.oa (.js:498:176)
at .js:557:378

Since a couple of days, code which worked fine to embed a YouTube video via Javascript stopped working. Now the video loads but it is not playable (the play button is not clickable), with this error in the console:

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

The JS code is as follows:

document.getElementById('player').setAttribute("style","height:"+(window.innerHeight * 0.87)+"px;");
document.getElementById('youtube_frame').src="http://www.youtube./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 also broke on another prototype that I run. Everything used to work fine until a couple of days ago. I cannot find anything online, perhaps someone can shed some light?

----- UPDATE ----

Embedding playback is broken again:

Uncaught TypeError: a.g.setActionHandler is not a function
at M_ (https://www.youtube./yts/jsbin/player-en_US-vflqOi6vK/base.js:3788:24)
at new N_ (https://www.youtube./yts/jsbin/player-en_US-vflqOi6vK/base.js:3783:111)
at new a2 (https://www.youtube./yts/jsbin/player-en_US-vflqOi6vK/base.js:3978:367)
at new g2 (https://www.youtube./yts/jsbin/player-en_US-vflqOi6vK/base.js:3999:210)
at g2.create (https://www.youtube./yts/jsbin/player-en_US-vflqOi6vK/base.js:6995:333)
at Gi.<anonymous> (https://www.youtube./yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:507:269)
at Gi.l.jb (https://www.youtube./yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:507:308)
at Ki (https://www.youtube./yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:505:143)
at Gi.l.oa (https://www.youtube./yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:498:176)
at https://www.youtube./yts/jsbin/www-embed-player-vfl-i_LLs/www-embed-player.js:557:378
Share Improve this question edited Feb 23, 2017 at 18:50 andrea-f asked Feb 13, 2017 at 1:04 andrea-fandrea-f 1,05510 silver badges24 bronze badges 7
  • 1 Seeing the same error message, but via the Google IMA HTML5 SDK. – almcd Commented Feb 13, 2017 at 11:44
  • @almcd, could it be related to CORS or HTTPS ? Because on youtube. there is the same error but the video plays fine. – andrea-f Commented Feb 13, 2017 at 23:06
  • Thanks for the suggestion @andrea-f . However, I’m no longer seeing the error message. Looks likely that Google’s fix has resolved the issue for the IMA SDK too. – almcd Commented Feb 14, 2017 at 12:37
  • @almcd yup, resolved – andrea-f Commented Feb 14, 2017 at 14:36
  • 2 @almcd yup already fixed, working again. – andrea-f Commented Feb 24, 2017 at 11:49
 |  Show 2 more ments

3 Answers 3

Reset to default 7

The issue has been resolved by Google and now YouTube videos play ok!

Wonder what happened?

----- UPDATE 23/02/2017 ------

Embedding playback is broken again:

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

I have this problem in Chrome 56.0.2924.87 (64-bit) when "experimental functions" are enabled.

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

We can disable this option here: chrome://flags/#enable-experimental-web-platform-features

-- UPDATE 10.03.2017 --

Chrome 57.0.2987.98 (64-bit) is published today and works fine!

Whatever the current problem is it is related to the MediaSession object while trying to attach an event (play in this case). This object is internal to Chrome so it seems something is corrupt there.

I'm seeing the same problem on any other website that uses YouTube - so don't waste your time trying to debug your own site. That's not the problem.

I've rebooted and tried to disable all extensions. Not seeing any fixes yet.

Mainly wanted to post this so people don't waste time thinking their code is bad.

发布评论

评论列表(0)

  1. 暂无评论