From 2589c5fac8827f281df618e10335ab8dec17c402 Mon Sep 17 00:00:00 2001
From: Lawrence <1934378145@qq.com>
Date: 星期一, 09 十一月 2020 18:44:35 +0800
Subject: [PATCH] 修正不同终端开关音频设置不同引起播放问题的bug
---
src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java | 74 +++++++++++++++++++++---------------
1 files changed, 43 insertions(+), 31 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
index 00f268c..978d152 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/play/PlayController.java
@@ -39,8 +39,10 @@
private ZLMRESTfulUtils zlmresTfulUtils;
@GetMapping("/play/{deviceId}/{channelId}")
- public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId) {
+ public ResponseEntity<String> play(@PathVariable String deviceId, @PathVariable String channelId,
+ Integer getEncoding) {
+ if (getEncoding == null) getEncoding = 0;
Device device = storager.queryVideoDevice(deviceId);
StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId);
@@ -64,40 +66,49 @@
long startTime = System.currentTimeMillis();
JSONObject rtpInfo = null;
- while (lockFlag) {
- try {
- if (System.currentTimeMillis() - startTime > 60 * 1000) {
- storager.stopPlay(streamInfo);
- logger.info("鎾斁绛夊緟瓒呮椂");
- return new ResponseEntity<String>("timeout", HttpStatus.OK);
- } else {
- streamInfo = storager.queryPlayByDevice(deviceId, channelId);
- if (!rtpPushed) {
- logger.info("鏌ヨRTP鎺ㄦ祦淇℃伅...");
- rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
- }
- if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null && streamInfo.getFlv() != null) {
- logger.info("鏌ヨ娴佺紪鐮佷俊鎭細" + streamInfo.getFlv());
- rtpPushed = true;
- Thread.sleep(2000);
- JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
- if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) {
- lockFlag = false;
- logger.info("娴佺紪鐮佷俊鎭凡鑾峰彇");
- JSONArray tracks = mediaInfo.getJSONArray("tracks");
- streamInfo.setTracks(tracks);
- storager.startPlay(streamInfo);
- } else {
- logger.info("娴佺紪鐮佷俊鎭湭鑾峰彇锛�2绉掑悗閲嶈瘯...");
- }
+ if (getEncoding == 1) {
+ while (lockFlag) {
+ try {
+ if (System.currentTimeMillis() - startTime > 60 * 1000) {
+ storager.stopPlay(streamInfo);
+ logger.info("鎾斁绛夊緟瓒呮椂");
+ return new ResponseEntity<String>("timeout", HttpStatus.OK);
} else {
- Thread.sleep(2000);
- continue;
+ streamInfo = storager.queryPlayByDevice(deviceId, channelId);
+ if (!rtpPushed) {
+ logger.info("鏌ヨRTP鎺ㄦ祦淇℃伅...");
+ rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
+ }
+ if (rtpInfo != null && rtpInfo.getBoolean("exist") && streamInfo != null
+ && streamInfo.getFlv() != null) {
+ logger.info("鏌ヨ娴佺紪鐮佷俊鎭細" + streamInfo.getFlv());
+ rtpPushed = true;
+ Thread.sleep(2000);
+ JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
+ if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) {
+ lockFlag = false;
+ logger.info("娴佺紪鐮佷俊鎭凡鑾峰彇");
+ JSONArray tracks = mediaInfo.getJSONArray("tracks");
+ streamInfo.setTracks(tracks);
+ storager.startPlay(streamInfo);
+ } else {
+ logger.info("娴佺紪鐮佷俊鎭湭鑾峰彇锛�2绉掑悗閲嶈瘯...");
+ }
+ } else {
+ Thread.sleep(2000);
+ continue;
+ }
}
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
- } catch (InterruptedException e) {
- e.printStackTrace();
}
+ } else {
+ String flv = storager.getMediaInfo().getLocalIP() + ":" + storager.getMediaInfo().getHttpPort() + "/rtp/"
+ + streamId + ".flv";
+ streamInfo.setFlv("http://" + flv);
+ streamInfo.setWs_flv("ws://" + flv);
+ storager.startPlay(streamInfo);
}
if (logger.isDebugEnabled()) {
@@ -136,3 +147,4 @@
}
}
}
+
--
Gitblit v1.8.0