Spring boot video streaming example-HTML5

Hello everyone, Today we will learn how to stream MP4 video using Spring. You can download the source code of this sample application from our GitHub repository. Download Link is provided at the end of this post.
User Interface 

Project Structure

Home Controller.class

public class HomeController {
private MyResourceHttpRequestHandler handler;
private final static File MP4_FILE =
new File("D:\\videofiles\\video1.mp4");

public String home() {
return "index";

// supports byte-range requests
public void byterange(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
request.setAttribute(MyResourceHttpRequestHandler.ATTR_FILE, MP4_FILE);
handler.handleRequest(request, response);

Spring Boot(Main class)

@ComponentScan({ "com" })
public class KnowledgefactorydemoApplication {
public static void main(String[] args) {
SpringApplication.run(KnowledgefactorydemoApplication.class, args);


public class MyResourceHttpRequestHandler extends ResourceHttpRequestHandler {
final static String ATTR_FILE = MyResourceHttpRequestHandler.class.getName() + ".file";

protected Resource getResource(HttpServletRequest request) throws IOException {
final File file = (File) request.getAttribute(ATTR_FILE);
return new FileSystemResource(file);


<div class="row align-items-center justify-content-center">
<video width="1000" height="400" controls>
<source src="byterange" type="video/mp4">
$ git clone  


  1. They helped expand the product offering the good web company thinking and implementation.


Post a Comment