视频的YouTube API结束装载函数 [英] youtube api end of video load a function
问题描述
我试图使用YouTube API时,检测到视频结束,然后调用一个函数JS我必须然后加载另一个。呼叫功能是在另一个.js文件这是我的HTML文档的头部。
这是code我从API的网站,到目前为止,但我与它真的很困惑。
I am trying to use the YouTube API to detect when a video ends and then to call a JS function I have to then load another one. The call function is in another JS document which is in the head of my HTML document. This is the code I have so far from the API site but I am really confused with it.
<pre><code> <script>
var ytfullplayer;
function onYouTubePlayerAPIReady() {
console.log('onYouTubePlayerAPIReady');
ytfullplayer = new YT.Player('myVid', {
events: {
if ''onStateChange': getVideo
}
});
}
function getVideo(); }
</script> </code> </pre>
我呼吁我的页面头部的YouTube API。但我不是100%肯定,如果去那里。
任何帮助将是很好。
我使用的是我的YouTube视频。
I have called the youtube api in the head of my page. But I am not 100% sure if it goes there. Any assistance would be nice. I am using an for my youtube video.
干杯
马特
推荐答案
该API提供你尝试下什么的订阅事件的:
The API provides an example of what you're attempting beneath Subscribing to Events:
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
绑定你的自定义函数作为处理程序的onStateChange事件,并从内部评估新的状态。根据API的事件部分,你要找的状态 0
,表示视频已经结束。
function onytplayerStateChange(newState) {
if ( newState == 0 ) {
/* load next video */
}
}
这篇关于视频的YouTube API结束装载函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!