如何使用Spring MVC返回视频,以便可以使用html5 标签进行导航?

如何使用Spring MVC返回视频,以便可以使用html5 标签进行导航?,第1张

如何使用Spring MVC返回视频,以便可以使用html5 标签进行导航?

处理非静态资源的简单解决方案:

@SpringBootApplicationpublic class DemoApplication {    private final static File MP4_FILE = new File("/home/ego/bbb_sunflower_1080p_60fps_normal.mp4");    public static void main(String[] args) {        SpringApplication.run(DemoApplication.class, args);    }    @Controller    final static class MyController {        @Autowired        private MyResourceHttpRequestHandler handler;        // supports byte-range requests        @GetMapping("/")        public void home(     HttpServletRequest request,     HttpServletResponse response        ) throws ServletException, IOException { request.setAttribute(MyResourceHttpRequestHandler.ATTR_FILE, MP4_FILE); handler.handleRequest(request, response);        }        // does not support byte-range requests        @GetMapping(path = "/plain", produces = "video/mp4")        public FileSystemResource plain() { return new FileSystemResource(MP4_FILE);        }    }    @Component    final static class MyResourceHttpRequestHandler extends ResourceHttpRequestHandler {        private final static String ATTR_FILE = MyResourceHttpRequestHandler.class.getName() + ".file";        @Override        protected Resource getResource(HttpServletRequest request) throws IOException { final File file = (File) request.getAttribute(ATTR_FILE); return new FileSystemResource(file);        }    }}

(受Spring Boots LogFileMvcEndpoint的启发,并且或多或少等于我稍后发现的Paul-Warrens(@ paul-warren)StoreByteRangeHttpRequestHandler)。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5004585.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存