Youtube Iframe: onYouTubePlayerAPIReady() not called

后端 未结 2 1085
别那么骄傲
别那么骄傲 2021-02-08 10:42

I have a page with an iframe which load a youtube video (the src of iframe is modified in runtime). I based on code by Rob W provided in different answers on this topic

2条回答
  •  半阙折子戏
    2021-02-08 11:00

    It seems like you're not closing the functions off correctly.

    The last } is closing off onYouTubePlayerAPIReady(), not dispose_ytplayer().

    Fixed code:

    function dispose_ytplayer() {
        (function(){
            var s = document.createElement("script");
            s.src = "http://www.youtube.com/player_api";
            var before = document.getElementsByTagName("script")[0];
            before.parentNode.insertBefore(s, before);
        })();
    
        alert('called yt_dispose');
    
        var ytIframeplayer;
    
        function onYouTubePlayerAPIReady() {
            alert('called onYouTubePlayerAPIReady');
            ytIframeplayer = new YT.Player('browser', {
                events: {
                    "onStateChange": stopCycle
                }
            });
        }
    }
    

提交回复
热议问题