use*_*960 5 java spring-mvc video-streaming
使用Spring MVC流式传输大型视频文件时遇到问题.我的源代码如下.因此,它可以播放小于10 MB的视频文件,但是当我播放72 MB的视频时,服务器会抛出以下异常:"ClientAbortException:java.net.SocketException:软件导致连接中止:套接字写入错误"
@RequestMapping(value = "/clip/{name}", method = RequestMethod.GET)
@ResponseBody
public void loadVideoFile(@PathVariable String name,
HttpServletResponse response) {
FileInputStream in = null;
ServletOutputStream out = null;
try {
if (bundle == null)
bundle = ResourceBundle.getBundle("course");
if (!bundle.containsKey("course.clip.Page" + name))
return;
String filePath = bundle.getString("course.clip.Page" + name);
int fileSize = (int) new File(filePath).length();
response.setContentLength(fileSize);
response.setContentType("video/mp4");
in = new FileInputStream(filePath);
out = response.getOutputStream();
int value = IOUtils.copy(in, out);
System.out.println("File Size :: " + fileSize);
System.out.println("Copied Bytes :: " + value);
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
response.setStatus(HttpServletResponse.SC_OK);
} catch (java.io.FileNotFoundException e) {
e.printStackTrace();
response.setStatus(HttpStatus.NOT_FOUND.value());
} catch (Exception e) {
e.printStackTrace();
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
}finally{
}
}
Run Code Online (Sandbox Code Playgroud)
我很感激任何帮助来解决这个问题.谢谢!
| 归档时间: |
|
| 查看次数: |
3217 次 |
| 最近记录: |