互联网网站排名,专业建站报价,九江 网站建设公司,本网站服务器在海外1 出发点及效果图 手机存储空间太小#xff0c;放不下几十级的视频#xff0c;网络看又太卡。这个小项目帮助大家在局域网中建立一个像youku一样的视频服务器#xff0c;这样就可以在家里通过局域网来观看服务 器#xff08;计算机#xff09;上的视频了。#xff08;不要…1 出发点及效果图 手机存储空间太小放不下几十级的视频网络看又太卡。这个小项目帮助大家在局域网中建立一个像youku一样的视频服务器这样就可以在家里通过局域网来观看服务 器计算机上的视频了。不要做羞羞的事情哟
2 原理 主要是利用了html中的vedio标签在tomcat服务器下播放指定文件夹中的mp4视频。 2.1 源码展示 2.1.1 获得视频列表的工具类
import java.util.ArrayList;public class file {private static String path E:/apache-tomcat-7.0.62/apache-tomcat-7.0.62/webapps/vedio;/*** * param dir* throws Exception*/static void showAllFiles(File dir) throws Exception {File[] fs dir.listFiles();for (int i 0; i fs.length; i) {System.out.println(fs[i].getName());if (fs[i].isDirectory()) {try {showAllFiles(fs[i]);} catch (Exception e) {}}}}public static ArrayListString getallfiles() throws Exception {File dir new File(path);File[] fs dir.listFiles();ArrayListString filelist new ArrayListString();for (int i 0; i fs.length; i) {System.out.println(fs[i].getName());if (fs[i].isDirectory()) {try {showAllFiles(fs[i]);} catch (Exception e) {}} else {filelist.add(fs[i].getName());}}return filelist;}public static void main(String[] args) {File root new File(path);try {showAllFiles(root);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}2.1.2 播放视频的jsp代码 % page languagejava importjava.util.* pageEncodingISO-8859-1%
%String path request.getContextPath();String basePath request.getScheme() :// request.getServerName() : request.getServerPort() path /;String vediopath (String) request.getAttribute(vediopath);
%!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN
html
head
base href%basePath%titleMy JSP playmyvedio.jsp starting page/titlemeta http-equivpragma contentno-cache
meta http-equivcache-control contentno-cache
meta http-equivexpires content0
meta http-equivkeywords contentkeyword1,keyword2,keyword3
meta http-equivdescription contentThis is my page
meta nameviewport contentwidthdevice-width, initial-scale1.0, minimum-scale1.0, maximum-scale1.0, user-scalableno,minimal-ui
!--link relstylesheet typetext/css hrefstyles.css--/headbodyvideo controls autobuffer source srchttp://192.168.7.101:8080/vedio/%vediopath%typevideo/mp4; codecsavc1.42E01E, mp4a.40.2/source /video
/body
/html
3 项目下载 http://download.csdn.net/detail/zhounanzhaode/8905437
4 使用 4.1 安装tomcat7.0以上版本
4.2 部署项目
4.3 在webapp目录下面建立vedio目录用来存放视频 5 局限
只能播mp4其它的没有试过有可能能播但是mp4效果是最好的。推荐用狸窝全能视频转换器转成mp4。