If I have a file on a web server (Tomcat) and create a tag, I can watch the video, pause it, move around it and restart it after it is complete.
But if I create a REST interface that sends a video file on demand and adds its URL to the tag, I can play and pause. No fast forward, no fast forward, no navigation , nothing.
So, is there a way to fix this? Am I missing something?
The video files are located on the same server as the REST interface , and the REST interface only checks the session and sends the video after finding out which one it should send.
These are the methods that I have tried so far. They all work, but not one of them allows navigation.
Method 1, ResponseEntity:
@RequestMapping(value = "/{id}/preview", method = RequestMethod.GET) @ResponseBody public ResponseEntity<byte[]> getPreview1(@PathVariable("id") String id, HttpServletResponse response) { ResponseEntity<byte[]> result = null; try { String path = repositoryService.findVideoLocationById(id); Path path = Paths.get(pathString); 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<byte[]>(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; }
Method 2, stream copy:
@RequestMapping(value = "/{id}/preview2", method = RequestMethod.GET) @ResponseBody public void getPreview2(@PathVariable("id") String id, HttpServletResponse response) { try { String path = repositoryService.findVideoLocationById(id); File file = new File(path) response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE); response.setHeader("Content-Disposition", "attachment; filename="+file.getName().replace(" ", "_")); InputStream iStream = new FileInputStream(file); IOUtils.copy(iStream, response.getOutputStream()); response.flushBuffer(); } catch (java.nio.file.NoSuchFileException e) { response.setStatus(HttpStatus.NOT_FOUND.value()); } catch (Exception e) { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); } }
Method 3, FileSystemResource:
@RequestMapping(value = "/{id}/preview3", method = RequestMethod.GET) @ResponseBody public FileSystemResource getPreview3(@PathVariable("id") String id, HttpServletResponse response) { String path = repositoryService.findVideoLocationById(id); return new FileSystemResource(path); }
java spring rest html5 video
Calabacin Dec 17 '13 at 12:48 2013-12-17 12:48
source share