YouTube iframe api(现有iframe);无法让iframe-api工作 [英] YouTube iframe api (existing iframe); Cannot get iframe-api to work
问题描述
我正在制作一个视频循环器,这将允许我们在一个网站上拥有多个视频;但只有其中一个很大。计划是在视频播放完毕后让它们自动循环。我打算使用onStateChange功能来确定何时应该循环它们。所有人都期待着我似乎无法使api工作。
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.
(使用不同的视频ID,因为真实视频尚未公开)
(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:
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)
}
日志:
无法加载资源:服务器响应状态为404(未找到)
Log: Failed to load resource: the server responded with a status of 404 (Not Found)
推荐答案
事实证明我的问题是视频的组合不公开,而没有我的服务器
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).
这篇关于YouTube iframe api(现有iframe);无法让iframe-api工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!