SCORM 1.2 Javascript函数

时间:2014-04-01 16:24:59

标签: javascript scorm

我正在使用Adobe Captivate创建简单的SCORM兼容包。要求是我只需要跟踪用户(学习者)正在观看视频的时间(total_time)。

我在页面上条纹化了媒体播放并插入了两个按钮。一个开始播放视频,另一个暂停播放。我现在正在寻找一个javascript函数,我可以调用它来启动时间,(在页面加载和单击PLAY按钮并在PAUSE上停止它。

这样的命令是否存在,这是最好的方法吗?

由于

1 个答案:

答案 0 :(得分:3)

虽然我没有使用Captivate课程对其进行测试,但我使用了一些关于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

参考文献:见herehere(滚动直至看到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


正如我所提到的,我没有迷人的课程代码。如果你在某处发布,我可以帮助你。