制作SCORM课件离线播放器(C#)

彭博 发布于 2012/03/09 12:24
阅读 2K+
收藏 0

概述

SCORM标准的课程是e-learning比较常用的标准,但课程要放到LMS浏览才看到课件数据的交互很不方便,下面介绍.net写的SCORM课件播放器,方便离线浏览SCORM课程或用于SCORM的课件测试。

主要实现

建立winform项目,向窗体添加web browser控件,添加窗体的Load,FormClosing事件

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace ScormPlayer

{

    [System.Runtime.InteropServices.ComVisibleAttribute(true)]

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

            webBrowser1.ObjectForScripting = this; //让html访问窗体的成员

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            string startupPath = System.Configuration.ConfigurationManager.AppSettings["StartupPath"];

            //课程的入口文件,写在配置文件里,方便修改

            string url = Path.Combine(Application.StartupPath, startupPath);

            //SCORM外壳页面,主要初始化SCORM API对象,把课程的地址当做参数传入

            string preview = Path.Combine(Application.StartupPath, "Preview.html?url=" + url);

            webBrowser1.Navigate(preview);

        }

        //关闭控制

        private bool _CanClose = false;

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)

        {

            if (!_CanClose)

            {

                //触发页面的onunload方法,让课件提交数据

                webBrowser1.Document.InvokeScript("eval", new object[] { "window.top.close()" });

                _CanClose = true;

            }

            e.Cancel = !_CanClose;

        }

    }

}

向窗体添加SCORM标准的API实现

        //SCORM API 对象

        public object API

        {

            get

            {

                return this;

            }

        }

 

        public string LMSInitialize(string value)

        {

            return "true";//没特殊处理返回"true"即可

        }

 

        public string LMSFinish(string value)

        {

            //课件页面unload时关闭窗体

            _CanClose = true;

            Close();

 

            return "true";//没特殊处理返回"true"即可

        }

 

        public string LMSGetValue(string model)

        {

            Util.Debug("LMSGetValue(" + model + ")");

            //TODO:读数据,添加自定义处理,可读写数据库或读写文件

            // string value;

            // ...

            // return value

            

            return "0";//返回指定的数据,这里hard code返回"0"。

        }

 

        public string LMSSetValue(string model, string value)

        {

            Util.Debug("LMSSetValue(" + model + ", " + value + ")");

            //TODO:写数据,添加自定义处理,可读写数据库或读写文件

 

            return "true";//没特殊处理返回"true"即可

        }

 

        public string LMSCommit(string value)

        {

            return "true";//没特殊处理返回"true"即可

        }

 

        public string LMSGetErrorString(string value)

        {

            return string.Empty;//没特殊处理返回""即可

        }

 

        public string LMSGetLastError()

        {

            return "0";//没特殊处理返回"0"即可

        }

 

        public string LMSGetDiagnostic(string value)

        {

            return string.Empty;//没特殊处理返回""即可

        }

添加SCORM外壳页面preview.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

<title>课程学习</title>

<script language="javascript" type="text/javascript">

window.API = window.external.API; //创建SCORM API对象,window.external.API是Form1.API属性

//获取地址参数

function getParam(paramName) {

    var url = unescape(window.location.href);

    var allargs = url.split("?")[1];

    var args = allargs.split("&");

    for (var i = 0; i < args.length; i++) {

        var arg = args[i].split("=");

        if (arg[0] == paramName) {

            return arg[1];

        }

    }

    return "";

}

function loadUrl() {

    var url = getParam("url");//课程的地址

    if (url != "") {

        document.getElementById("content").src = url;

    }

}

</script>

<style>

html{height: 100%;}

body{height: 100%;margin: 0px;overflow: hidden;}

</style>

</head>

<body onload="loadUrl()">

<iframe id="content" name="content" width="100%" height="100%" frameborder="0" scrolling="no" src="">iframe>

<noframes>

</noframes>

</body>

</html>

配置文件配置课程的入口文件

xml version="1.0" encoding="utf-8" ?>

<configuration>

    <appSettings>

        <add key="StartupPath" value="Course3/index.html"/>

    <!--<add key="StartupPath" value="Course1/Player.html"/>

         <add key="StartupPath" value="Course2/lo/template.html"/>

         <add key="StartupPath" value="Course3/index.html"/>

         -->

    </appSettings>

</configuration>

进阶

上面基本实现了SCORM标准,进一步完善,可以进行课程数据的存储,上载课程数据到平台,添加课程管理等功能,才算真正实现企业级的SCORM离线播放器。


原文链接:http://blog.csdn.net/hunkcai/article/details/5301610
加载中
返回顶部
顶部