从Spring MVC中的Apache tomcat服务器目录流式传输HTML页面中的视频 [英] stream a video in html page from apache tomcat server directory in spring mvc
问题描述
我想从本地(Apache Tomcat)服务器目录播放xyz.mp4格式的视频.我已经在服务器目录中的webapps下创建了一个文件夹. 预先感谢..
I want to play video with xyz.mp4 format from local (apache tomcat)server directory. I've created a folder under webapps in server directory. Thanks in advance..
@RequestMapping(value = "admin/videoplay", method = RequestMethod.GET)
public String videoplay(Model model,
HttpServletRequest req, HttpServletResponse res) {
File objFile=new File("D:\\server tomcat\\webapps\\UPLOADS\\Videos\\SetWet.mp4");
model.addAttribute("video", objFile);
return "videoplay";
}
<html>
<body>
<video controls="controls">
<source src="shuttle.mp4" type="video/mp4">
<source src="shuttle.ogv" type="video/ogg">
Your browser does not support the HTML5 Video element.
</video>
</body>
</html>
推荐答案
您无法在Model
中设置视频文件,并假定它将在HTML Player中播放.
You can't set the video file in Model
and assume that it will play in the HTML Player.
HTML Video Player需要一个视频文件源,它是字节流.在Model
中发送文件不会将其作为字节流化.
An HTML Video Player requires a video file source which is a Stream of Bytes. Sending a file in a Model
will not stream it as Bytes.
看看我一段时间做了的帖子背部.您可以使用Spring的StreamingResponseBody
来实现播放.完整的源代码可在 github
Have a look at the post I did sometime back. You can do achieve the playing by using Spring's StreamingResponseBody
. Full source code available in github
这篇关于从Spring MVC中的Apache tomcat服务器目录流式传输HTML页面中的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!