| | |
| | | /** |
| | | * 开启直播 |
| | | */ |
| | | public void StartLiveStreaming(String sn) { |
| | | public void StartLiveStreaming(String sn, String videotype ) { |
| | | // 检查设备是否在线 |
| | | if (!_deviceService.checkDeviceOnline(sn)) { |
| | | String jsonString = getResult(sn, "设备不在线,请检查网络连接!"); |
| | | log.info("SN: {}-设备不在线,请检查网络连接!", sn); |
| | | _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), jsonString); |
| | | return; |
| | | } |
| | |
| | | List<CapacityDeviceDTO> devicesList = _liveStreamService.getLiveCapacity(); |
| | | if (devicesList == null || devicesList.isEmpty()) { |
| | | String jsonString = getResult(sn, "未获得设备直播能力!"); |
| | | log.info("SN: {}-未获得设备直播能力!", sn); |
| | | _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), jsonString); |
| | | return; |
| | | } |
| | |
| | | param.setUrl(""); |
| | | param.setVideoId(videoid); |
| | | param.setVideoQuality(1); |
| | | param.setVideoType(video.getSwitchVideoTypes().get(0)); |
| | | param.setVideoType(videotype); |
| | | //调用开始直播 |
| | | ResponseResult rlive = null; |
| | | String resultLive = ""; |
| | | try { |
| | | rlive = _liveStreamService.liveStart(param); |
| | | if (rlive != null) { |
| | | if (rlive.getCode() == 513003) { |
| | | // if (rlive.getCode() == 513003) { |
| | | while (rlive.getCode() == 513003) { |
| | | //Thread.sleep(200); |
| | | _liveStreamService.liveStop(param.getVideoId()); |
| | | System.out.println("相机已经在直播中,关闭直播后重启直播!"); |
| | | //System.out.println("相机已经在直播中,关闭直播后重启直播!"); |
| | | log.info("SN: {}-相机已经在直播中,关闭直播后重启直播!", sn); |
| | | rlive = _liveStreamService.liveStart(param); |
| | | } |
| | | if(rlive.getCode() == 0){ |
| | | // 直播成功后,在redis中存一个标记,将videoid保留,留给停止直播使用 |
| | | System.out.println("开启直播成功!"); |
| | | //System.out.println("开启直播成功!"); |
| | | log.info("SN: {}-开启直播成功!", sn); |
| | | RedisOpsUtils.setWithExpire(RedisConst.WEBSOCKET_VideoId_PREFIX + sn, param.getVideoId(), RedisConst.WEBSOCKET_ALIVE_SECOND); |
| | | rlive.setGateway(sn); |
| | | } |
| | | rlive.setGateway(sn); |
| | | rlive.setType(MessageType.LIVESTREAM.getType()); |
| | | resultLive = _objectMapper.writeValueAsString(rlive); |
| | | _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive); |
| | | log.info("SN: {}-直播地址:{}", sn, resultLive); |
| | | break; |
| | | } |
| | | rlive.setType(MessageType.LIVESTREAM.getType()); |
| | | resultLive = _objectMapper.writeValueAsString(rlive); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | _dockWebSocketHandler.sendMessageToSubscribers(sn, MessageType.LIVESTREAM.getType(), resultLive); |
| | | break; |
| | | } |
| | | } |
| | | } |