《课件播放系统组件使用方法》由会员分享,可在线阅读,更多相关《课件播放系统组件使用方法(11页珍藏版)》请在金锄头文库上搜索。
1、搭建课件上传下载及播放文件上传模块前台页面提交文件前台页面验证脚本$(document).ready(function() $(document.form).submit(function()var file = (document.getElementById(file).value;var name = .ppt;if(file.indexOf(name,file.length-4) 请选择需上传的教学课件(课件格式为 PPT):后台上传模块public class AddVideoAction extends ActionSupportprivate static final long
2、serialVersionUID = 1L;private static final int BUFFER_SIZE = 8 *1024;private File uploadFile;private VideoService vs;private String uploadFileFileName;private String uploadFileContentType;public VideoService getVs() return vs;public void setVs(VideoService vs) this.vs = vs;/上传到服务器private static void
3、 copy(File src,File dst)tryInputStream in = null;OutputStream os = null;tryin = new BufferedInputStream(new FileInputStream(src);os = new BufferedOutputStream(new FileOutputStream(dst),BUFFER_SIZE);byte buffer = new byteBUFFER_SIZE;while( in.read(buffer) 0)os.write(buffer);finallyif(null != in)in.cl
4、ose();if(null != os)os.close();catch (Exception e)e.printStackTrace();public String execute()throws ExceptionSimpleDateFormat sdf = new SimpleDateFormat(yyyyMMddHHmmss);if(null=ActionContext.getContext().getSession().get(currentAdmin)return login;String fileName = uploadFileFileName;fileName = fileN
5、ame.replace( ,);String playFileName = sdf.format(new Date()+.flv;File playFile = new File(ServletActionContext.getServletContext().getRealPath(/upload/video/play) + + playFileName);File downloadFile = new File(ServletActionContext.getServletContext().getRealPath(/upload/video/download) + + fileName)
6、;copy(uploadFile,downloadFile);copy(uploadFile,playFile);if( 1 = vs.addVideo(downloadFile,playFileName)return SUCCESS;return ERROR;/文件的扩展名public static String getExtention(String fileName)int pos = fileName.lastIndexOf(.);return fileName.substring(pos);public File getUploadFile() return uploadFile;p
7、ublic void setUploadFile(File uploadFile) this.uploadFile = uploadFile;public String getUploadFileFileName() return uploadFileFileName;public void setUploadFileFileName(String uploadFileFileName) this.uploadFileFileName = uploadFileFileName;public String getUploadFileContentType() return uploadFileC
8、ontentType;public void setUploadFileContentType(String uploadFileContentType) this.uploadFileContentType = uploadFileContentType;文件下载模块文件下载模块public class DownLoadFileAction extends ActionSupportprivate static final long serialVersionUID = 1L;private String fileName;private String type;public String
9、contentType; private VideoService vs ;private PPtService ps;private int id;public int getId() return id;public void setId(int id) this.id = id;public VideoService getVs() return vs;public void setVs(VideoService vs) this.vs = vs;public PPtService getPs() return ps;public void setPs(PPtService ps) th
10、is.ps = ps;public InputStream getDownloadFile() if(type.equals(ppt)contentType = application/vnd.ms-powerpoint;return ServletActionContext.getServletContext().getResourceAsStream(/upload/ppt/+getDownLoadChineseFileName();elsecontentType =application/x-shockwave-flash;return ServletActionContext.getS
11、ervletContext().getResourceAsStream(/upload/video/download/+getDownLoadChineseFileName();public String getDownLoadChineseFileName()String downloadChineseFileName = fileName;trydownloadChineseFileName = new String (downloadChineseFileName.getBytes(ISO8859-1),gbk);System.out.println(downloadChineseFil
12、eName);catch(UnsupportedEncodingException e)e.printStackTrace();return downloadChineseFileName;public String execute() throws Exception if(type.equals( ppt)ps.updateDtime(id);elsevs.updateDtime(id);/ServletActionContext.getResponse().setHeader(Content-Disposition,attachment;filename= + getDownLoadCh
13、ineseFileName();return SUCCESS;public String getFileName() return getDownLoadChineseFileName();public void setFileName(String fileName) this.fileName = fileName;public String getType() return type;public void setType(String type) this.type = type;public void setContentType(String contentType) this.c
14、ontentType = contentType; public String getContentType() return contentType; 下载的配置文件$contentTypeattachment;filename=$fileNamedownloadFile4096 contentType 指定下载文件的文件类型 application/octet-stream 表示无限制inputName 流对象名 比如这里写 inputStream,它就会自动去找 Action 中的 getInputStream 方法。contentDisposition 使用经过转码的文件名作为下载文件
15、名 默认格式是 attachment;filename=$fileName,将调用该 Action 中的 getFileName 方法。bufferSize 下载文件的缓冲大小文件在线播放模块Get the Flash Player to see this rotator.var s1 = new SWFObject(imagerotator.swf,rotator,600,480,8);s1.addParam(allowfullscreen,true);s1.addVariable(file,);s1.addVariable(width,600);s1.addVariable(height,480);s1.addVariable(shuffle,false);s1.addVariable(rotatetime,5);s1.addVariable(icons,true);s1.addVariable(autostart,false);s1.write(container);后台处理 PPT 模块package com.hbv.service;import java.io.File;import java.text.SimpleDateFormat;import java.util.Date;i