我通过YouTube数据API将视频拉到网站上,并希望在视频暂停或完成时注册回调。一旦这些操作发生,是否会触发事件?是否有一种方法可以检测视频是否已经暂停或完成?
订阅事件
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
关于https://developers.google.com/youtube/js_api_reference#SubscribingEvents的更多信息