gpt4 book ai didi

javascript - Captivate HTML5 Module Youtube 视频播放器状态

转载 作者:行者123 更新时间:2023-12-03 06:06:13 24 4
gpt4 key购买 nike

我们使用 Adob​​e 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() wildcard
上面的代码适用于 youtube direct,但不适用于 HTML5。
谢谢您的帮助。

最佳答案

我已经能够让它工作了。我必须做的是:
在 Captivate 中,您可以设置高级交互,您可以在其中添加自定义 JS。从那里我在脚本中添加了向 LRS 发送消息以进行播放、暂停等。
我们正在制作一个带有自定义控件的模板,因此任何使用这些模板发布的人都可以启用报告。
enter image description here

关于javascript - Captivate HTML5 Module Youtube 视频播放器状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63495563/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com