| | |
| | | |
| | | while (lockFlag) { |
| | | try { |
| | | |
| | | if (System.currentTimeMillis() - startTime > 15 * 1000) { |
| | | storager.stopPlay(streamInfo); |
| | | return new ResponseEntity<String>("timeout",HttpStatus.OK); |
| | | }else { |
| | | streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
| | | JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId); |
| | | if (rtpInfo == null || !rtpInfo.getBoolean("exist") || storager.queryPlayByDevice(deviceId, channelId).getFlv() == null){ |
| | | if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo.getFlv() != null){ |
| | | JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); |
| | | if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) { |
| | | lockFlag = false; |
| | | JSONArray tracks = mediaInfo.getJSONArray("tracks"); |
| | | streamInfo.setTracks(tracks); |
| | | storager.startPlay(streamInfo); |
| | | }else { |
| | | |
| | | } |
| | | }else { |
| | | Thread.sleep(2000); |
| | | continue; |
| | | }else { |
| | | lockFlag = false; |
| | | streamInfo = storager.queryPlay(streamInfo); |
| | | // 获取媒体信息 |
| | | JSONObject mediaList = zlmresTfulUtils.getMediaList("rtp", "rtmp"); |
| | | if (mediaList.getInteger("code") == 0) { |
| | | JSONArray data = mediaList.getJSONArray("data"); |
| | | if (data!= null) { |
| | | for (Object datum : data) { |
| | | JSONObject media = (JSONObject)datum; |
| | | if (streamId.equals(media.getString("stream"))) { |
| | | streamInfo.setTracks(media.getJSONArray("tracks")); |
| | | storager.startPlay(streamInfo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | } |
| | | streamInfo = storager.queryPlayByDevice(deviceId, channelId); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |