最爱吃苹果 2021-12-13 21:02 采纳率: 0%
浏览 22

Springboot+vue后台播放接口不管怎么改,只播放同一个视频



```java
  @GetMapping("/video")
    public void videoPreview(HttpServletRequest request, HttpServletResponse response) throws Exception {

        String sourcePath = ClassUtils.getDefaultClassLoader().getResource("").getPath().substring(1);
        String realPath = sourcePath +"static/video/1.mp4";
        String realPath2 = sourcePath +"static/video/5.mp4";

**不管怎么改realpath的值都只播同一个视频
**
        Path filePath = Paths.get(realPath2);
        if (Files.exists(filePath)) {
            String mimeType = Files.probeContentType(filePath);
            if (!StringUtils.isEmpty(mimeType)) {
                response.setContentType(mimeType);
            }
            request.setAttribute(NonStaticResourceHttpRequestHandler.ATTR_FILE, filePath);
            nonStaticResourceHttpRequestHandler.handleRequest(request, response);
        } else {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            response.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        }


    }

```

  • 写回答

1条回答 默认 最新

  • 技术专家团-极简 2021-12-13 21:12
    关注

    你写死的realPath2,只用了这个路径的视频。

    评论

报告相同问题?

问题事件

  • 创建了问题 12月13日