1. 程式人生 > >後臺讀取圖片、視訊顯示到前端頁面

後臺讀取圖片、視訊顯示到前端頁面

@RequestMapping("stream")
	public void getStreamData(HttpServletResponse response) {
		File file=new File("C:\\avi_vedio\\test.avi");
		ServletOutputStream out=null;
		try {
			FileInputStream instream=new FileInputStream(file);
			byte[] b=new byte[1024];
			int length=0;
			BufferedInputStream buf=new BufferedInputStream(instream);
			out=response.getOutputStream();
			BufferedOutputStream bot=new BufferedOutputStream(out);
			while((length=buf.read(b))!=-1) {
				bot.write(b,0, b.length);
			}
		} catch (Exception  e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

前端:

<body>
       <video width="320" height="240" controls>
		    <source src="http://localhost:8080/sjsc/wechatapp/violationitem/stream" 
            type="video/mp4">
	   </video>
	</body>