1.先上传视频或图片,并把路径保存在数据库里(怎么上传就不说了,网上很多)。
我的是把视频存放到F盘fileUpload文件夹下:
0){
imagesPath = imagesPath.substring(0, imagesPath.indexOf(".jar"));
}else if(imagesPath.indexOf("classes")>0){
imagesPath = "file:"+imagesPath.substring(0, imagesPath.indexOf("classes"));
}
imagesPath = imagesPath.substring(0, imagesPath.lastIndexOf("/"))+"/images/";
mImagesPath = imagesPath;
}
LoggerFactory.getLogger(WebAppConfig.class).info("imagesPath="+mImagesPath);
registry.addResourceHandler("/images/**").addResourceLocations(mImagesPath);
// TODO Auto-generated method stub
System.out.print("2.上传配置类mImagesPath=="+mImagesPath+"n");
super.addResourceHandlers(registry);
}
}
3.读取数据库中的图片或视频路径,返回url:
例如:数据库中视频保存路径:F:/fileUpload/20180808105540_aa.mp4
读取到这个路径,拼接成:
http://localhost:8088/images/20180808105540_aa.mp4
直接放到浏览器就可以播放了: