YouTube iframe api (existing iframe); Cannot get iframe-api to work

懵懂的女人 提交于 2019-12-11 08:31:18

问题


I am making a "video cycler" which will allow us to have multiple videos on one website; but only have one of them large. The plan was to have them "auto cycle" when the video is finished playing. I was going to use the onStateChange feature to figure out when I should cycle them. All is going well expect for the fact that I cannot seem to get the api to work.

(using a different videoID because the real video isn't public yet)

HTML:

<iframe id="video0" width="640" height="385" src="https://www.youtube.com/embed/dREeDjQ0jIg?rel=0&enablejsapi=1&origin=*" frameborder="0" allowfullscreen></iframe>

JavaScript:

var player;
function onYouTubeIframeAPIReady() {
    video = document.getElementById('video0');
    player = new YT.Player(video, {
        events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
            }
        })
    }
function onPlayerReady(e) {
    console.log("hey Im ready");
    }
function onPlayerStateChange(e) {
    console.log(e)
    }

Log: Failed to load resource: the server responded with a status of 404 (Not Found)


回答1:


It turns out that my issue was the a combo of the video not being public and not having my server in the

&origin=SERVER_URL/IP

I listed out the full path to my file (it was a local server, so I did some port forwarding).




回答2:


I don't think there is any problem with the iframe ! since the real video is not public yet error 404 is what you can expect !



来源:https://stackoverflow.com/questions/21668815/youtube-iframe-api-existing-iframe-cannot-get-iframe-api-to-work

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