| | |
| | | import com.sun.jna.Platform; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.boot.ApplicationArguments; |
| | | import org.springframework.boot.ApplicationRunner; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | |
| | | **/ |
| | | @Service |
| | | @Slf4j(topic = "cmd") |
| | | public class MediaServiceImpl implements IMediaService { |
| | | @Order(1) |
| | | public class MediaServiceImpl implements IMediaService, ApplicationRunner { |
| | | @Resource |
| | | VtduMapper vtduMapper; |
| | | @Resource |
| | |
| | | |
| | | String processName = "mediamtx.exe"; |
| | | |
| | | static{ |
| | | |
| | | @Override |
| | | public void run(ApplicationArguments args) throws Exception { |
| | | log.info("开始加载流媒体列表"); |
| | | List<StreamInfo> paths = paths(); |
| | | for(StreamInfo path:paths) |
| | | { |
| | | mediaClient.removePath(path.getName()); |
| | | } |
| | | List<Vtdu> vtduList = vtduMapper.selectVtduList(new Vtdu()); |
| | | for (Vtdu v : vtduList) { |
| | | addPath(v.getName(), v.getRtspUrl(), v.getCodeType(), v.getIsCode()); |
| | | } |
| | | } |
| | | @PostConstruct |
| | | public void initMediaMtx() { |
| | | if (mediamtxEnabled) { |
| | | log.info("初始化启动mediaMTX"); |
| | | if (Platform.isWindows()) { |
| | | String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.exe"; |
| | | String ymlPath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.yml"; |
| | |
| | | // String[] command = {"cmd","/c","start",exePath,ymlPath}; |
| | | // CmdUtils.commandStart(command); |
| | | } |
| | | } |
| | | try { |
| | | Thread.sleep(2000); // 等待5秒 |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | List<StreamInfo> paths = paths(); |
| | | for(StreamInfo path:paths) |
| | | { |
| | | mediaClient.removePath(path.getName()); |
| | | } |
| | | List<Vtdu> vtduList = vtduMapper.selectVtduList(new Vtdu()); |
| | | for (Vtdu v : vtduList) { |
| | | addPath(v.getName(), v.getRtspUrl(), v.getCodeType(), v.getIsCode()); |
| | | } |
| | | } |
| | | |
| | |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | } |