title: How to stream videos in Spring MVC?
body: <p>I want to load a video file from my local directory ("E:\video") and display it using JW Player in my Spring MVC web application. The JW Player does not play video files, it simply displays the loading icon.</p>
  
  <p>My front-end player setup:</p>
  
  <pre class="lang-js prettyprint-override"><code>$(function() {
    var vplayer = jwplayer("playerDiv").setup({
      'flashplayer': '../../player.swf',
      'id': 'playerID',
      'width': '440',
      'height': '380',
      'mute': false,
      'volume': '100',
      'file': 'spring/loadVideoFile',
      'controlbar': 'bottom',
      'provider': 'video'
    });
    vplayer.play();
  });
  </code></pre>
  
  <p>My request handler:</p>
  
  <pre><code>@RequestMapping(value = "/loadVideoFile", method = RequestMethod.GET)
  @ResponseBody public void loadVideoFile(HttpServletResponse response) {
      try {           
          String filePath = "E://video//26.mov";        
          int fileSize = (int) new File(filePath).length();
          response.setContentLength(fileSize);
          response.setContentType("video/quicktime");
          FileInputStream inputStream = new FileInputStream(filePath);
          ServletOutputStream outputStream = response.getOutputStream();
          int value = IOUtils.copy(inputStream, outputStream);
          System.out.println("File Size :: "+fileSize);
          System.out.println("Copied Bytes :: "+value);
          IOUtils.closeQuietly(inputStream);
          IOUtils.closeQuietly(outputStream);
          response.setStatus(HttpServletResponse.SC_OK);
      } catch (java.io.FileNotFoundException e) {         
          response.setStatus(HttpStatus.NOT_FOUND.value());
      } catch (Exception e) {         
          response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
      }
  }
  </code></pre>
  
  <p>How the JW Player appears:</p>
  
  <p><img src="https://i.stack.imgur.com/nAUYu.png" alt="enter image description here"></p>