Erd*_*mir 1 spring video-streaming html5-video spring-boot spring-restcontroller
使用spring boot,我想制作基于RESTful的视频播放器.我的文件浏览器中有.mp4扩展视频.如何通过创建休息端点在前端端提供这些视频?
我试过这种方法.视频可以启动或停止.但它无法向后或向前完成.无法达到所需的时间并开始.
Spring Content支持开箱即用的视频流.使用Spring Content作为文件系统(FS),您可以自己创建一个由文件系统支持的视频存储,将您的视频放在该存储中,并使用配套库Spring Content REST通过HTTP为它们提供服务.任何前端视频播放器.
通过start.spring.io或通过IDE spring项目向导(编写本文时的Spring Boot 1.5.10)创建一个新的Spring Boot项目.添加以下Spring Content依赖项,以便最终得到以下内容: -
<dependencies>
<!-- Standard Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.3</version>
</dependency>
<!-- Spring Content -->
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-fs-boot-starter</artifactId>
<version>0.0.9</version>
</dependency>
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-rest-boot-starter</artifactId>
<version>0.0.9</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
在Spring Boot Application类中,创建一个VideoStore.将其注释为Store REST资源.这会导致Spring Content注入一个实现(文件系统的这个接口)以及为这个接口添加REST端点,这样你就不必自己编写任何一个:
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@StoreRestResource(path="videos")
public interface VideoStore extends Store<String> {}
}
Run Code Online (Sandbox Code Playgroud)
默认情况下,Spring Content将在java.io.tmpdir下创建一个商店.因此,您还需要将SPRING_CONTENT_FS_FILESYSTEM_ROOT环境变量设置为指向"store"的根目录.
将您的视频复制到此"根"位置.启动应用程序,您的视频将可以从以下链接流式传输: -
/videos/MyVideo.mp4
| 归档时间: |
|
| 查看次数: |
9008 次 |
| 最近记录: |