javascript - SCORM 1.2 JavaScript 函数

标签 javascript scorm

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

我在页面上对媒体播放进行了 strip 化​​,并插入了两个按钮。一个用于开始播放视频,另一个用于暂停视频。我现在正在寻找一个 JavaScript 函数,我可以调用它来启动时间(在页面加载和单击“播放”按钮上并在“暂停”时停止它。

这样的命令是否存在,这是执行此操作的最佳方法吗?

谢谢

最佳答案

虽然我没有 Captivate 类(class)来测试这一点,但我使用了一些有关 captivate SCORM 代码的文档

我创建了四个函数 - 一个是电影开始时的函数,一个是暂停时的函数,一个是类(class)即将结束且需要计算时间的函数,还有一个用于格式化 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

引用文献:参见here或者 here (滚动直到看到 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


正如我所提到的,我没有 captivate 类(class)代码。如果您将其发布到某个地方,我可以进一步帮助您。

关于javascript - SCORM 1.2 JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22791526/

相关文章:

javascript - 如何向 amCharts 中的向下钻取饼图添加多个监听器

javascript - 找出对象表示法中数组的长度

javascript - flatMap 代替 for of

javascript - Backbone Undefined 不是函数错误

javascript - 研究替代方案 : integrate SCORM and LMS without frames

javascript - 在 SCORM 中跟踪 HTML5 变量

javascript - 如何清除此 JavaScript cookie?

javascript - 从一张幻灯片跳到另一张幻灯片

c# - 将 SCORM eLearning 集成到 .NET 应用程序中 - 我应该从哪里开始?

php - 如何以编程方式为自定义事件创建 scorm 包?