使用 spring boot,我想制作基于 RESTful 的视频播放器。我的文件浏览器中有 .mp4 扩展名的视频。如何通过创建休息端点在前端提供这些视频?
我已经尝试过这个方法。 http://shazsterblog.blogspot.com.tr/2016/02/asynchronous-streaming-request.html视频可以开始或停止。但这不能向后或向前进行。无法达到所需的分钟并启动。
春季内容 https://paulcwarren.github.io/spring-content/支持开箱即用的视频流。使用 Spring Content 作为文件系统 (FS),您将能够自己创建一个由文件系统支持的视频存储,将您的视频放入该存储中,并使用配套库 Spring Content REST 通过 HTTP 为它们提供服务任何前端视频播放器。
通过 start.spring.io 或通过 IDE spring 项目向导创建一个新的 Spring Boot 项目(撰写本文时 Spring Boot 1.5.10)。添加以下 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>
在您的 Spring Boot 应用程序类中,创建一个 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> {}
}
默认情况下,Spring Content 将在 java.io.tmpdir 下创建一个存储。因此,您还需要设置 SPRING_CONTENT_FS_FILESYSTEM_ROOT 环境变量以指向“商店”的根目录。
将您的视频复制到此“根”位置。启动应用程序,您的视频将从以下位置传输:-
/videos/MyVideo.mp4
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)