我们使用 Adobe Captivate 创建 HTML5 模块,然后托管在我们的网站上。希望是从视频中获取播放器状态。IE 播放、暂停、跳过、停止。
如果我使用此处的说明将视频直接放在页面中:
https://developers.google.com/youtube/iframe_api_reference
没问题,视频运行,我得到我的播放器状态。
当我尝试对迷人的模块做同样的事情时,我无法让我的 JS 运行。
我很确定这是因为我无法确定页面上元素的 ID。当我检查它时,我得到:
<div id="SlideVideo_2" class="cp-frameset" style="z-index: 0; display: block; left: 320px; top: 165px; width: 640px; height: 390px; transform: rotate(0deg);"></div>
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: 'wLlovxa3VJ0',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
alert(event.data);
if (event.data == YT.PlayerState.PLAYING && !done) {
setTimeout(stopVideo, 6000);
done = true;
}
}
function stopVideo() {
player.stopVideo();
}
我尝试使用 SlideVideo_2 和 getElementby ID 和通配符: getElementById() 通配符
上面的代码适用于 youtube direct,但不适用于 HTML5。
谢谢您的帮助。