SpringBoot静态视频实时播放的实现代码

  

  

弹簧引导API定义得到请求API,返回视频流。前端通过& lt; video>标签加载并播放视频,效果是必须等整个视频资源全部加载到浏览器才能播放,而且& lt; video>标签默认的进度条无法控制视频的播放。最终希望的效果是视频流边加载边播放,且播放器的控制正常使用。

  

  

Spring框架文件请求处理<强>
  

        进口org.springframework.core.io.FileSystemResource;   进口org.springframework.core.io.Resource;   进口org.springframework.stereotype.Component;   进口org.springframework.web.servlet.resource.ResourceHttpRequestHandler;      进口javax.servlet.http.HttpServletRequest;   进口java.nio.file.Path;      @ component   公开课NonStaticResourceHttpRequestHandler延伸ResourceHttpRequestHandler {      最后公共静态字符串ATTR_FILE=癗ON-STATIC-FILE”;      @Override   getResource (HttpServletRequest请求受保护的资源){   最终路径filePath=(路径)request.getAttribute (ATTR_FILE);   返回新FileSystemResource (filePath);   }      }      之前      

控制器层
  

        @RestController   @AllArgsConstructor   公开课FileRestController {      私人最终NonStaticResourceHttpRequestHandler NonStaticResourceHttpRequestHandler;/* *   *预览视频文件,支持字节范围请求   */@GetMapping(/视频)   公共空间videoPreview (HttpServletRequest请求,HttpServletResponse响应){抛出异常   字符串路径=request.getParameter(“路径”);   filePath=Paths.get路径(路径);   如果(Files.exists (filePath)) {   字符串mimeType=Files.probeContentType (filePath);   如果(! StringUtils.isEmpty (mimeType)) {   response.setContentType (mimeType);   }   request.setAttribute (NonStaticResourceHttpRequestHandler。ATTR_FILE filePath);   nonStaticResourceHttpRequestHandler。handleRequest(请求、响应);   其他}{   response.setStatus (HttpServletResponse.SC_NOT_FOUND);   response.setCharacterEncoding (StandardCharsets.UTF_8.toString ());   }   }      }      之前      

相关资料
  

  

我怎么返回一个视频与Spring MVC,这样就可以将导航使用html5标签# 63;

  https://stackoverflow.com/questions/3303029/http-range-header

  

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

SpringBoot静态视频实时播放的实现代码