我正在与一起创建简单的SCORM兼容包。要求我只需要跟踪用户(学习者)观看视频的时间(total_time)。
我在页面上对媒体播放进行了条带化,并插入了两个按钮。一个开始播放视频,另一个暂停它。我现在正在寻找一个javascript函数,我可以调用它来启动时间,(在页面加载和点击PLAY按钮,并在暂停时停止它。
这样的命令存在吗?这是最好的方法吗?
谢谢
发布于 2014-04-02 04:47:35
虽然我没有一个Captivate课程来测试这一点,但是我使用了一些关于SCORM代码的文档
我创建了四个函数--一个在电影开始时,一个在暂停时,一个在课程即将结束时,时间需要计算,另一个是为scorm格式化时间,scorm是一种简单的HH:MM:SS.S.格式。
Note: that you mentioned total_time or cmi.core.total_time, this is a read only
attribute, a course should send the session time and the LMS computes the
cmi.core.total_time参考资料:请参阅这里或这里 (滚动直到您看到cmi.core.session_time)
在脚本标记的末尾添加以下代码:
var mod_elapsedSeconds = 0;
var mod_startTime;
function sco_start(){
if ( mod_startTime != 0 )
{
var currentDate = new Date().getTime();
mod_elapsedSeconds += ( (currentDate - mod_startTime) / 1000 );
}
mod_startTime = new Date().getTime();
}
function sco_pause(){
if ( mod_startTime != 0 )
{
var currentDate = new Date().getTime();
mod_elapsedSeconds += ( (currentDate - mod_startTime) / 1000 );
}
mod_startTime = 0;
}
function onB4LMSFinish(){
if ( mod_startTime != 0 )
{
var currentDate = new Date().getTime();
mod_elapsedSeconds += ( (currentDate - mod_startTime) / 1000 );
var formattedTime = convertTotalSeconds( mod_elapsedSeconds );
}
else
{
formattedTime = "00:00:00.0";
}
Captivate_DoFSCommand( "cmi.core.session_time", formattedTime );
}
function convertTotalSeconds(ts)
{
var sec = (ts % 60);
ts -= sec;
var tmp = (ts % 3600); //# of seconds in the total # of minutes
ts -= tmp; //# of seconds in the total # of hours
// convert seconds to conform to CMITimespan type (e.g. SS.00)
sec = Math.round(sec*100)/100;
var strSec = new String(sec);
var strWholeSec = strSec;
var strFractionSec = "";
if (strSec.indexOf(".") != -1)
{
strWholeSec = strSec.substring(0, strSec.indexOf("."));
strFractionSec = strSec.substring(strSec.indexOf(".")+1, strSec.length);
}
if (strWholeSec.length < 2)
{
strWholeSec = "0" + strWholeSec;
}
strSec = strWholeSec;
if (strFractionSec.length)
{
strSec = strSec+ "." + strFractionSec;
}
if ((ts % 3600) != 0 )
var hour = 0;
else var hour = (ts / 3600);
if ( (tmp % 60) != 0 )
var min = 0;
else var min = (tmp / 60);
if ((new String(hour)).length < 2)
hour = "0"+hour;
if ((new String(min)).length < 2)
min = "0"+min;
var rtnVal = hour+":"+min+":"+strSec;
return rtnVal;
}更改如下所示的标记:
<body bgcolor="#f5f4f1" onunload="Finish();">至:
<body bgcolor="#f5f4f1" onunload="onB4LMSFinish();Finish();">将这些函数添加到“开始”和“暂停”按钮:
sco_start(); // for starting the video
sco_pause(); // for pausing正如我提到的,我没有迷人的课程代码。如果你把它贴在某个地方,我可以进一步帮你。
https://stackoverflow.com/questions/22791526
复制相似问题