文件名称:实现视频在线播放.zip
文件大小:2KB
文件格式:ZIP
更新时间:2023-07-12 18:05:52
java ,HTML视频在线播放 video标签
java后端代码: @RequestMapping("/outputVideo") public void getVideo(HttpServletRequest request,HttpServletResponse response,@RequestParam("path")String videoPath) throws IOException { System.out.println("来请求了!路径:"+videoPath); //1.创建地址 URL readUrl = new URL("file:///"+videoPath); //2.创建连接对象; URLConnection urlConnection =readUrl.openConnection(); //3.设置超时时间; urlConnection.setConnectTimeout(1000); urlConnection.setReadTimeout(50000); urlConnection.connect(); //3.获取流 InputStream inputStream= urlConnection.getInputStream(); //4.获取文件格式 String format= "MP4"; if (format.equalsIgnoreCase("mp4")) { response.addHeader("Content-Type","video/mp4;cahrset:utf-8"); }else { System.out.println("格式有误!"); } IOUtils.copy(inputStream, response.getOutputStream()); response.flushBuffer(); System.out.println("输出成功!"); } HTML前端接response收流:
【文件预览】:
实现视频在线播放
----video.html(448B)
----VideoFile.java(1KB)