文档,影音的的在线浏览

实现文档,音频视频在线浏览
1.后台写法

@RequestMapping(value="onLineBrowseOfficeDoc")
    public ModelAndView onLineBrowseOfficeDoc(@Context HttpServletRequest request, 
                    @Context HttpServletResponse response)
    {
        ModelAndView mv = new ModelAndView();
        PageData pd = this.getPageData();

        try 
        {
            String requestUrl = request.getRequestURL().toString();
            String contentName = request.getContextPath();
            int contentNameIndex = requestUrl.indexOf(contentName);
            String serverPath = requestUrl.substring(0, contentNameIndex + 1);

            PageData pdd = dataResourcesFacade.findById(pd);
            String reletivePath = pdd.getString("RI_URL").replace("1_ADMIN", "1_admin");

            String root = getContextRealPath();             //获取工程根路径
            String filePath = root + reletivePath;

            File file = new File(filePath);
            boolean isExists = file.exists();               //文件不存在,返回null
            if(!isExists){
                mv.setViewName("system/noExist");
                mv.addObject("pd", pd);
                return mv;
            }

            int index = filePath.lastIndexOf(".");
            String fileExt = filePath.substring(index + 1);

            String tempContentName = contentName.substring(1);
            String returnPath = serverPath + tempContentName + "/" + reletivePath;
            int convertResult = -1;
            if(fileExt != null && !fileExt.equals("") && fileExt.equalsIgnoreCase("pdf"))
            {
                returnPath = returnPath.replaceAll("\\\\", "/");

                pd.put("pdfsrc", returnPath);
                mv.setViewName("meeting/PdfViewer");
                mv.addObject("pd", pd);
                return mv; 
            }
            else if(fileExt.equalsIgnoreCase("doc") 
                        || fileExt.equalsIgnoreCase("docx")
                        || fileExt.equalsIgnoreCase("xls")
                        || fileExt.equalsIgnoreCase("xlsx")
                        || fileExt.equalsIgnoreCase("ppt")
                        || fileExt.equalsIgnoreCase("pptx"))
            {
                filePath = filePath.replaceAll("\\\\", "/");
                index = filePath.lastIndexOf("/");

                File returnFolder = new File(filePath.substring(0, index));
                if(!returnFolder.exists())
                    returnFolder.mkdirs();
                returnPath = filePath.substring(0, filePath.lastIndexOf(".")) + ".pdf";


                File file2 = new File(returnPath);
                boolean isExists2 = file2.exists();             //文件不存在则进行转换
                if(!isExists2){
                    convertResult = office2PDF(filePath, returnPath);
                }else{
                    convertResult=0;
                }
            }
            else if (fileExt.equalsIgnoreCase("mp4")
                    || fileExt.equalsIgnoreCase("avi")
                    || fileExt.equalsIgnoreCase("mp3")
                    || fileExt.equalsIgnoreCase("aac")
                    || fileExt.equalsIgnoreCase("wav")
                    || fileExt.equalsIgnoreCase("ogg")) 
            {
                returnPath = returnPath.replaceAll("\\\\", "/");

                pd.put("pdfsrc", returnPath);
                pd.put("suffixName",fileExt);
                mv.setViewName("meeting/fileViewVideo");
            /*  mv.setViewName("meeting/VideoViewer");*/
                mv.addObject("pd", pd);
                return mv;
            } 
/*            else if (fileExt.equalsIgnoreCase("avi")
                    || fileExt.equalsIgnoreCase("wmv")
                    || fileExt.equalsIgnoreCase("3gp")
                    || fileExt.equalsIgnoreCase("mpg")
                    || fileExt.equalsIgnoreCase("flv")
                    || fileExt.equalsIgnoreCase("mov")) 
            {
                returnPath = returnPath.replaceAll("\\\\", "/");

                pd.put("pdfsrc", returnPath);
                mv.setViewName("meeting/VideoViewer");
                mv.setViewName("meeting/fileViewVideo");
                mv.addObject("pd", pd);
                return mv;
//              filePath = filePath.replaceAll("\\\\", "/");
//              index = filePath.lastIndexOf("/");
//
//              File returnFolder = new File(filePath.substring(0, index));
//              if (!returnFolder.exists())
//                  returnFolder.mkdirs();
//              returnPath = filePath.substring(0, filePath.lastIndexOf("."))
//                      + ".mp4";
//
//              File file2 = new File(returnPath);
//              boolean isExists2 = file2.exists(); // 文件不存在则进行转换
//              if (!isExists2) {
//                  convertResult = Video2MP4(filePath, returnPath);
//              } else {
//                  convertResult = 0;
//              }
//              pd.put("pdfsrc", returnPath);
//              mv.setViewName("meeting/PdfViewer");
//              mv.addObject("pd", pd);
//              return mv; 
            }*/ else
                return null;
            if(convertResult == 0)
            {
                returnPath = serverPath + returnPath.substring(returnPath.indexOf(contentName) + 1);
                //returnPath="http://127.0.0.1:8080/DIIT-Web-OneMap/uploadFiles/1_admin/Document/123.pdf";
                //pd.put("pdfsrc",  URLEncoder.encode(returnPath,"utf-8"));
                pd.put("pdfsrc",  returnPath);
                mv.setViewName("meeting/PdfViewer");
                mv.addObject("pd", pd);
                return mv;
            }
        }
        catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return null;
    }

2文档类前端写法

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ page isELIgnored="false" %> 
<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">

    <title>pdf在线浏览</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="icon" type="image/png" href="static/assets/images/sign_Logo.png">


    <script type="text/javascript" src="static/js/jquery-1.9.1.min.js"></script>

    <script type="text/javascript" src="static/js/pdfobject.js"></script>

    <style>
        html,body,.pdfobject-container{
            height:100%;
            width:100%;
            margin:0px;
            padding:0px;
        }
    </style>

  </head>

  <body>

    <div id="pdfDiv"></div>

    <script>
//      $(".pdfobject-container").height($(document).height());
        var src = "${pd.pdfsrc}";
        PDFObject.embed(src, "#pdfDiv");
    </script>

  </body>
</html>

3.在线音视频浏览

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
 <link href="<%=basePath%>static/js/video/css/video-js.css" rel="stylesheet">       
    <style>
         #container,#table{      
            position: fixed;
            top: 0px;
            left: 0px;
            right: 0px;
            bottom: 0px;
            margin: auto;
            display:none;
    }

    </style>
<script type="text/javascript" src="<%=basePath%>static/js/jwplayer-7.2.2/jwplayer.js"></script>
<script type="text/javascript" src="<%=basePath%>static/js/jwplayer-7.2.2/provider.shaka.js"></script>
<script type="text/javascript">jwplayer.key="W+FSSIJICMeqqi4MQCwmdLePq9iq8HQqiVT5dQ==";</script>
<script>
$(function() { 
var suffixName='${pd.suffixName}';
alert(suffixName);

});
function userJWPlayer(){
 jwplayer ( "container" ). setup ({

           flashplayer : "<%=basePath%>static/js/jwplayer-7.2.2/jwplayer.flash.swf" ,

           file : "<%=basePath%>uploadFiles/1_admin/AudioVisual/test.mp4" ,

           height : 600,

           width : 800

      });

}
</script>
</head>
<body bgcolor=aquamarine>
 <div id = "container">Loading the player ...</div>
   <table width=100% height=100% id="table">
        <tr>

            <td align="center" valign="middle"><object id="video1"
                    classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="800"
                    height="500" type="application/x-mplayer2" border="0">

                    <param name="ShowDisplay" value="0">
                    <param name="ShowControls" value="1">
                    <param name="AutoStart" value="-1">
                    <param name="AutoRewind" value="0">
                    <param name="PlayCount" value="1">
                    <param name="Appearance value=" 0 value=""">
                    <param name="BorderStyle value=" 0 value=""">
                    <param name="MovieWindowHeight" value="500">
                    <param name="MovieWindowWidth" value="800">
                    <embed width="900" height="600" border="0" showdisplay="0"
                        showcontrols="1" playcount="0"
                        src="<%=basePath%>uploadFiles/1_admin/AudioVisual/Chains.aac">

                    </embed>
                </object></td>
        </tr>
    </table> 
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值