我目前正在使用youtube API调用视频:
<div id="ytapiplayer">
You need Flash player 8+ and JavaScript enabled to view this video.
</div>
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF(
"http://www.youtube.com/v/TEHWDA_6e3M?enablejsapi=1&playerapiid=ytplayer&version=3",
"ytapiplayer",
"960",
"540",
"8",
null,
null,
params,
atts
);
但是,我需要在播放视频时发生一些事情。
我一直试图用这个: https://developers.google.com/youtube/js_api_reference#Adding_event_listener 像这样:
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
虽然我之前从未使用过这个级别的javascript,也没有使用过API。