因为客户机的访问不到政务云存储的ip, 所以决定使用后台返回视频和图片流到前端
注意: 如果上边返回的流会导致图片不清晰或者马赛克, 请使用下边注释的代码返回流
前端视频用的是ckplayer
@RequestMapping("/getViewImg1")
public void execute1(HttpServletResponse response,@RequestParam(value="imgPath") String imgPath){
//由于数据库存的是绝对路径,之前的老数据只能这样转换了
imgPath=imgPath.replace("http://zkyt-yc.oss-cn-ningxia-a-internal.aliyuncs.com/", "http://zkyt-yc.oss-cn-yc-yczw-d01-a.yc-ops.nxcloud.com.cn/");
System.out.println("路径-"+imgPath);
try {
if(imgPath.indexOf("http")>-1) {
URL url = null;
InputStream input = null;
try{
url = new URL(imgPath);
HttpURLConnection httpUrl = (HttpURLConnection) url.openConnection();
httpUrl.connect();
httpUrl.getInputStream();
input = httpUrl.getInputStream();
}catch (Exception e) {
e.printStackTrace();
return;
}
response.setContentType(url.openConnection().getContentType());
ServletOutputStream out=response.getOutputStream();
try {
byte[] buf = new byte[2048];
while(input.read(buf)>=0){
out.write(buf);
}
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}finally{
if(input!=null){
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
// 如果边返回的流会导致图片不清晰或者马赛克, 请使用下边注释的代码返回流
} catch (Exception e) {
// TODO: handle exception
}
}
前端视频代码



