title: Implement Byte serving for Spring Boot
body: <p>I want to implement video Player in Angular using Spring Boot Rest API. I can play the video but I can't make video seeking. Every time the video starts over and over again when I use Chrome or Edge.</p>
  <p>I tried this endpoint:</p>
  <pre><code>@RequestMapping(value = &quot;/play_video/{video_id}&quot;, method = RequestMethod.GET)
      @ResponseBody public ResponseEntity&lt;byte[]&gt; getPreview1(@PathVariable(&quot;video_id&quot;) String video_id, HttpServletResponse response) {
          ResponseEntity&lt;byte[]&gt; result = null;
          try {
              String file = &quot;/opt/videos/&quot; + video_id + &quot;.mp4&quot;;
              Path path = Paths.get(file);
              byte[] image = Files.readAllBytes(path);
  
              response.setStatus(HttpStatus.OK.value());
              HttpHeaders headers = new HttpHeaders();
              headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
              headers.setContentLength(image.length);
              result = new ResponseEntity&lt;byte[]&gt;(image, headers, HttpStatus.OK);
          } catch (java.nio.file.NoSuchFileException e) {
              response.setStatus(HttpStatus.NOT_FOUND.value());
          } catch (Exception e) {
              response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
          }
          return result;
      }
  </code></pre>
  <p>I found this post which gives some ides: <a href="https://stackoverflow.com/questions/28427339/how-to-implement-http-byte-range-requests-in-spring-mvc">How to Implement HTTP byte-range requests in Spring MVC</a></p>
  <p>But currently it's not working. Video is again playing from the start when I try to shift the position.</p>
  <p>I use this player: <a href="https://github.com/smnbbrv/ngx-plyr" rel="nofollow noreferrer">https://github.com/smnbbrv/ngx-plyr</a></p>
  <p>I have configured it this way:</p>
  <pre><code>&lt;div class=&quot;media&quot;&gt;
          &lt;div
            class=&quot;class-video mr-3 mb-1&quot;
            plyr
            [plyrPlaysInline]=&quot;true&quot;
            [plyrSources]=&quot;gymClass.video&quot;
            (plyrInit)=&quot;player = $event&quot;
            (plyrPlay)=&quot;played($event)&quot;&gt;
          &lt;/div&gt;
          &lt;div class=&quot;media-body&quot;&gt;
            {{ gymClass.description }}
          &lt;/div&gt;
        &lt;/div&gt;
  </code></pre>
  <p>Do you know how I can fix this issue?</p>