Harinder
Harinder

Reputation: 11

stream a video in html page from apache tomcat server directory in spring mvc

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>

Screenshot

Upvotes: 1

Views: 2040

Answers (1)

shazin
shazin

Reputation: 21883

You can't set the video file in Model and assume that it will play in the HTML Player.

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.

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

Upvotes: 2

Related Questions