我最近一直在学习春季靴框架,到目前为止,我对此印象深刻。
但是,我一直在尝试编写基本的媒体服务器应用程序,但我不确定如何实现服务于HTML 5视频源的控制器端点的正确方法。我目前已经这样实现了:
@GetMapping(value = "/videosrc", produces = "video/mp4")
@ResponseBody
public FileSystemResource videoSource(@RequestParam(value="id", required=true) int id) {
return new FileSystemResource(new File("path to mp4 file"));
}
和HTML 5视频元素看起来像这样:(使用百里叶(
<video width="auto" height="240" controls style=" margin-left: auto; margin-right: auto; display: block;">
<source th:src="@{/videosrc(id=${video.id})}" type="video/mp4">
</video>
视频显示,但是我注意到,如果我跳过几次视频,它最终会减慢,然后冻结浏览器。我不确定为什么会发生这种情况,但我认为这是因为我没有正确处理请求?
谢谢
您应该考虑一个名为Spring Content的Spring Boot Companion Project,该项目允许您使用很少的代码创建数字资产管理应用程序。
给您一个看起来像这样的基本想法: -
pom.xml
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-rest-boot-starter</artifactId>
<version>0.0.10</version>
</dependency>
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>content-fs-spring-boot-starter</artifactId>
<version>0.0.10</version>
</dependency>
springbootapplication.java
@SpringBootApplication
public class YourSpringBootApplication {
public static void main(String[] args) {
SpringApplication.run(YourSpringBootApplication.class, args);
}
@Configuration
@EnableFilesystemStores
public static class StoreConfig {
File filesystemRoot() {
// return the root of your video store
}
// this bean is the spring resource loader that will be used by
// the product store
@Bean
public FileSystemResourceLoader fsResourceLoader() throws Exception
{
return new FileSystemResourceLoader(filesystemRoot().getAbsolutePath());
}
}
@StoreRestResource(path="videosrc")
public interface VideoStore extends Store<String> {
//
}
}
请注意,您没有在此处编写任何控制器代码,但这足以在/videosrc
上创建REST视频服务,该服务支持完整的CRUD和视频流(即字节范围(。create == post,read == get(包括字节范围支持(,update == put,delete == delete。
,例如
POST /videosrc/some/path/video1.mp4
会将上传的多部分视频存储到/some/path/video.mp4。
春季内容也可以与春季数据结合使用,以存储和搜索这些视频的元数据。如果这很有趣,请查看这里和这里的入门指南。
这看起来可能只是Firefox(Quantum(的问题 - 它可以正常工作,但是在跳过几次后似乎冻结了。
我在Google Chrome上对此进行了测试,并且效果很好。在移动浏览器上也可以正常工作。
我还检查了它正在发送正确的HTTP标头 - 主要是"接受范围:字节"(是(。