| | |
| | | //package com.whyc.listener; |
| | | // |
| | | //import com.whyc.constant.YamlProperties; |
| | | //import com.whyc.dto.Response; |
| | | //import com.whyc.service.VideoService; |
| | | //import org.springframework.beans.factory.annotation.Autowired; |
| | | // |
| | | //import javax.servlet.ServletContext; |
| | | //import javax.servlet.ServletContextEvent; |
| | | //import javax.servlet.ServletContextListener; |
| | | //import javax.servlet.annotation.WebListener; |
| | | //import java.util.List; |
| | | // |
| | | //import static java.lang.Thread.sleep; |
| | | // |
| | | ///** |
| | | // * 应用启动时初始化 |
| | | // * 应用关闭时销毁 |
| | | // */ |
| | | //@WebListener |
| | | //public class ApplicationListener implements ServletContextListener { |
| | | // |
| | | // @Autowired |
| | | // private VideoService videoService; |
| | | // |
| | | // /** |
| | | // * 1.初始化,开启视频流并启动录像存储 |
| | | // * @param servletContextEvent |
| | | // */ |
| | | // @Override |
| | | // public void contextInitialized(ServletContextEvent servletContextEvent) { |
| | | // ServletContext application = servletContextEvent.getServletContext(); |
| | | // //考虑意外情况:突然程序死机或者电脑断电重启,需要延时启动录像,因为视频推流服务还未完成. |
| | | // try { |
| | | // //延时20s |
| | | // sleep(20000); |
| | | // } catch (InterruptedException e) { |
| | | // throw new RuntimeException(e); |
| | | // } |
| | | // |
| | | // |
| | | // //1.录像存储 |
| | | // //获取所有的流id |
| | | // List<String> videoStreamIds = YamlProperties.videoStreamIds; |
| | | // //开启录像存储 |
| | | // videoStreamIds.forEach(streamId -> { |
| | | // //添加流 |
| | | // Response<String> response = videoService.addStreamProxy(streamId); |
| | | // |
| | | // //判断是否在录像,不在的话,开启录像 |
| | | // |
| | | // Response response2 = videoService.startRecord(streamId); |
| | | // if(!(response2.getCode() ==1 && ((boolean) response2.getData()))){ |
| | | // System.out.println("流id为:"+streamId+"的信息:"+response2.getMsg()); |
| | | // }else{ |
| | | // System.out.println("流id为:"+streamId+"的信息:"+response2.getData()); |
| | | // } |
| | | // }); |
| | | // |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void contextDestroyed(ServletContextEvent servletContextEvent) { |
| | | // //关闭所有流 |
| | | // //videoService.closeStreams(); |
| | | // } |
| | | //} |
| | | package com.whyc.listener; |
| | | |
| | | import com.whyc.constant.YamlProperties; |
| | | import com.whyc.dto.IpInfo; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.service.VideoService; |
| | | import com.whyc.util.HikTempUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import javax.servlet.ServletContext; |
| | | import javax.servlet.ServletContextEvent; |
| | | import javax.servlet.ServletContextListener; |
| | | import javax.servlet.annotation.WebListener; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | | import static java.lang.Thread.sleep; |
| | | |
| | | /** |
| | | * 应用启动时初始化 |
| | | * 应用关闭时销毁 |
| | | */ |
| | | @WebListener |
| | | public class ApplicationListener implements ServletContextListener { |
| | | |
| | | @Autowired |
| | | private VideoService videoService; |
| | | |
| | | /** |
| | | * 1.初始化,开启视频流并启动录像存储 |
| | | * @param servletContextEvent |
| | | */ |
| | | @Override |
| | | public void contextInitialized(ServletContextEvent servletContextEvent) { |
| | | ServletContext application = servletContextEvent.getServletContext(); |
| | | //初始化hik sdk |
| | | HikTempUtil.init(); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void contextDestroyed(ServletContextEvent servletContextEvent) { |
| | | //关闭hik sdk |
| | | HikTempUtil.logoutAndCleanup(HikTempUtil.lUserIDs); |
| | | } |
| | | } |