小编Ind*_*Ots的帖子

使用Spring MVC流式传输大型视频

使用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); …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc video-streaming

5
推荐指数
0
解决办法
3217
查看次数

标签 统计

java ×1

spring-mvc ×1

video-streaming ×1