java - 如何使用 Spring RESTful Web 服务观看视频

标签 java spring web-services rest html5-video

我尝试从 Spring Restful Web 服务中读取视频。 我的网络服务是用 SpringBoot (tomcat) 启动的,我的 html 是在 apache http 服务器上加载的。

我可以观看或下载视频,但我无法在视频中自定义时间跳转。 当可以从网络服务(src="http://localhost:8080/maVideo")访问视频时存在这个问题,但是当从apache服务器(src="media/maVideo")访问视频时不存在这个问题").

这是我的 Java 代码:

@CrossOrigin
@RequestMapping(value = "/videoSimple/{hash}", method = RequestMethod.GET, headers = "Accept=application/media")
public ResponseEntity<InputStreamResource> videoSimple(final HttpSession session, @PathVariable final String hash) throws IOException {

    final String fileName = "/4_videoToto.mp4";
    final ClassPathResource classPathResource = new ClassPathResource("medias/" + fileName);
    final HttpHeaders headers = createHttpHeaders(fileName, classPathResource);

    final ResponseEntity<InputStreamResource> response = new ResponseEntity<>(new InputStreamResource(classPathResource.getInputStream()), headers, HttpStatus.OK);
    return response;
}

这是我的 html 代码。

<video id="video_telechargeable" width="360" height="250" controls>
        <source src="http://localhost:8080/maVideo" type="video/mp4">
</video>

你知道这个麻烦吗?

最佳答案

我找到了这个类的解决方案:MultpartFileSender -> https://gist.github.com/davinkevin/b97e39d7ce89198774b4

关于java - 如何使用 Spring RESTful Web 服务观看视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38693796/

相关文章:

java - JIRA6 REST API - HttpClient 和 HttpClientCache JAR 冲突

java - DHTMLX 调度程序日期和时间未保存到数据库

java - 带有 Google GWT 插件的 Spring Tool Suite 在 Java2HTMLEntityReader 中引发错误

web-services - 如何在 JMeter bean shell 断言中打印变量的值

java - 如何将 json 字符串转换为 java 列表?

java - Java IO 是阻塞 IO 吗?

java - msgraph-sdk-java 中对 beta API 的支持

javascript - Thymeleaf 在 Google Analytics 代码上抛出错误

Spring Cache - 仅当 API 响应成功时才清除缓存

java - 如何使用webservice和axis2从android将图像存储在mysql数据库中?