ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java-Spring Boot HTML 5视频流

2019-11-09 05:01:57  阅读:166  来源: 互联网

标签:html5 spring-boot thymeleaf html5-video java


我最近一直在学习Spring启动框架,到目前为止,我对它印象深刻.

但是,我一直在尝试编写一个基本的媒体服务器应用程序,但我不完全确定实现提供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视频元素如下所示:(使用Thymeleaf)

<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配套项目,该项目使您可以用很少的代码来创建数字资产管理应用程序.

为您提供基本概念,如下所示:-

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中创建支持完整CRUD和视频流(即字节范围)的REST视频服务.创建== POST,读取== GET(包括字节范围支持),更新== PUT,删除== DELETE.

例如

开机自检/videosrc/some/path/video1.mp4

会将上传的分段视频存储到/some/path/video.mp4.

Spring Content也可以与Spring Data结合使用,以存储和搜索有关这些视频的元数据.如果有兴趣,请参阅入门指南herehere.

标签:html5,spring-boot,thymeleaf,html5-video,java
来源: https://codeday.me/bug/20191109/2011932.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有