StreamServerConfig.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package com.coyee.stream.config;
  2. import lombok.Data;
  3. import lombok.extern.slf4j.Slf4j;
  4. import org.apache.commons.io.FileUtils;
  5. import org.springframework.boot.context.properties.ConfigurationProperties;
  6. import org.springframework.stereotype.Component;
  7. import javax.annotation.PostConstruct;
  8. import javax.annotation.Resource;
  9. import java.io.File;
  10. import java.io.IOException;
  11. import java.util.List;
  12. /**
  13. * @author hxfein
  14. * @className: StreamServerConfig
  15. * @description: 流服务配置
  16. * @date 2022/5/12 14:32
  17. * @version:1.0
  18. */
  19. @Component
  20. @Data
  21. @ConfigurationProperties("streamserver")
  22. @Slf4j
  23. public class StreamServerConfig {
  24. /**
  25. * 加密key
  26. */
  27. private String desKey;
  28. /**
  29. * 转为hls协议时m3u8、TS文件的存储目录
  30. */
  31. private String hlsStoreDir;
  32. /**
  33. * 单个分片播放时间
  34. */
  35. private int hlsTime = 5;
  36. /**
  37. * 最大分片数
  38. */
  39. private int hlsWrap = 20;
  40. /**
  41. * 播放列表数
  42. */
  43. private int hlsListSize = 10;
  44. /**
  45. * 没有观众时流的关闭时间,-1为不关闭
  46. */
  47. private long expireMills = 1000 * 60 * 5;
  48. /**
  49. * 系统启动时,先把hlsStoreDir里面的文件清除掉
  50. */
  51. @PostConstruct
  52. public void onStreamServerStart() throws IOException {
  53. File dir = new File(hlsStoreDir);
  54. if (dir.exists() == false) {
  55. dir.mkdir();
  56. }
  57. log.info("准备清除hls目录的残留文件");
  58. File[] children = dir.listFiles();
  59. for (File child : children) {
  60. if (child.isDirectory()) {
  61. FileUtils.deleteDirectory(child);
  62. log.info("目录 已被清除:{}", child.getAbsolutePath());
  63. } else {
  64. FileUtils.deleteQuietly(child);
  65. log.info("文件 已被清除:{}", child.getAbsolutePath());
  66. }
  67. }
  68. }
  69. }