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 simple application from our GitHub repository. The Source code download Link is provided at the end of this post.

User Interface 

Project Structure


A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details utilized by Maven to build the project. It contains default values for most projects.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
<!-- lookup parent from repository -->
<!-- spring mvc, rest -->

Home Controller.class

We indite a controller class to handle requests emanating from the client. The @Controller annotation indicates that a particular class serves the role of a controller.
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);


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);

Spring Boot(Main class)

A Spring Boot application's main class is a class that contains a public static void main() method that commences up the Spring ApplicationContext. By default, if the main class isn't explicitly designated, Spring will probe for one in the classpath at compile time and fail to commence if none or multiple of them are found.

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


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


$ mvn spring-boot:run

App running at: 

More Topics:


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

  2. They maintained open lines of communication throughout the engagement. The team's professional yet collaborative approach set them apart from other providers.
    brand marketing firm

  3. They were consistently great at communication and have been asked to work on several more projects.
    top app design consultancies

  4. With their talent, they have provided great results. Customers can expect excellent communication from the team.
    top brand agency


Post a Comment