有一个名为Spring Content 的Spring 社区项目。它支持字节范围请求,因此支持开箱即用的 html5 视频控件。我不确定这是否足够好?
无论如何,当与 Spring Data(和 Spring Boot)配对时,这个项目使得构建内容应用程序和服务变得非常容易。它具有与 Spring Data 相同的编程模型,本质上是内容(或非结构化数据),就像 Spring 数据对结构化数据一样。即使它对于流媒体来说还不够好(我们很高兴与您合作来增强这一点),它肯定会帮助您加快整体“内容管理”平台的构建,因为您可能需要用户/管理页面允许人们上传和管理您的视频流。
这可能类似于以下内容:-
pom.xml
<!-- Spring Boot/ Spring Data dependencies -->
...
<!-- Java API -->
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-fs-boot-starter</artifactId>
<version>0.7.0</version>
</dependency>
<!-- REST API -->
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-rest-boot-starter</artifactId>
<version>0.7.0</version>
</dependency>
视频.java
@Entity
public class Video {
@Id
@GeneratedValue
private long id;
...other existing fields...
@ContentId
private String contentId;
@ContentLength
private long contentLength = 0L;
@MimeType
private String mimeType = "text/plain";
...
}
VideoContentStore.java
@StoreRestResource(path="videoStreams")
public interface VideoContentStore extends ContentStore<Video, String> {
}
这就是您获取 REST 端点所需要做的一切,这将允许您存储和检索与每个视频实体关联的内容。如前所述,这实际上是如何工作的,非常类似于 Spring Data。当您的应用程序启动时,Spring Content 将看到 spring-content-fs-boot-starter 依赖项,知道您想要在文件系统上存储内容并注入 VideoContentStore 接口的文件系统(或 JPA/GridFS/S3)实现。它还将看到 spring-content-rest-boot-starter 并将注入与此内容存储接口对话的 REST 端点。这意味着您不必自己做任何事情。
所以,例如:
curl -X POST /videoStreams/{videoId} -F "file=@/path/to/video.mp4"
将视频存储在文件系统中,并将其与 id 为 videoId 的视频实体相关联。
curl /videoStreams/{videoId}
将再次获取它等等...支持完整的 CRUD,这是端点也支持视频流(或字节范围请求)。
有一个例子here。
您还可以决定将内容存储在其他地方,例如与您的实体一起存储在数据库中,或者通过将 spring-content-fs-boot-starter 依赖项交换为适当的 Spring Content Storage 模块来存储在 S3 中。每种存储类型的示例是here。
HTH
附言不要羞于提出我们正在积极寻求参与的问题/功能请求和/或 PR。