spring - 基于 Restful 的视频流

标签 spring spring-boot video-streaming html5-video spring-restcontroller

使用spring boot,我想制作基于RESTful的视频播放器。我的文件浏览器中有 .mp4 扩展名的视频。如何通过创建休息端点在前端提供这些视频?

I've tried this method.视频可以开始或停止。但这不能向后或向前进行。无法达到所需的分钟并开始。

最佳答案

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 注入(inject)一个实现(文件系统的此接口(interface)),并为此接口(interface)添加 REST 端点,这样您就不必自己编写任何一个接口(interface)了:-

    @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

关于spring - 基于 Restful 的视频流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48201031/

相关文章:

java - 按计划进行缓存驱逐后,Spring 缓存未被使用

spring-boot - spring-boot-actuator 是否会改变 spring 应用程序的上下文根?

apache-flex - 如何获取流的名称(RTMFP NetGroup问题,Flex/AS3)

javascript - 如何在网络浏览器上通过 Live555 服务器的 rtsp 协议(protocol)流式传输视频

iphone - 如何在iPhone中实现视频聊天

java - Spring/Hibernate 和关系映射

spring - 如何使用 WebClient 压缩 JSON 请求正文?

java - 没有默认构造函数的 Autowire Bean,使用配置注释

spring - SpringSecurity : Fail to delete JSESSIONID

java - 在实体内增加值(likeCount)而不会遇到并发问题