|
|
@ -5,19 +5,17 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.dromara.business.config.ZlmConfig; |
|
|
|
import org.dromara.business.service.BusinessVideoService; |
|
|
|
import org.dromara.business.service.IBusinessVideoService; |
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Service |
|
|
|
@Slf4j |
|
|
|
@RequiredArgsConstructor |
|
|
|
public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
public class BusinessVideoServiceImpl implements IBusinessVideoService { |
|
|
|
|
|
|
|
private final ZlmConfig zlmConfig; |
|
|
|
private static final ObjectMapper objectMapper = new ObjectMapper(); |
|
|
@ -27,6 +25,7 @@ public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
@Override |
|
|
|
public Boolean startRecording() { |
|
|
|
|
|
|
|
Boolean result = false; |
|
|
|
String url = String.format("%s%s?app=%s&stream=%s&type=%s&vhost=%s&secret=%s", |
|
|
|
zlmConfig.getApiUrl(), |
|
|
|
zlmConfig.getStartRecordUrl(), |
|
|
@ -44,19 +43,22 @@ public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
try { |
|
|
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); |
|
|
|
if (response.getStatusCode().is2xxSuccessful()) { |
|
|
|
Map<String, Object> result = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
log.info("录制启动成功: {}", result); |
|
|
|
Map<String, Object> resultMap = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
result = (Boolean) resultMap.get("status"); |
|
|
|
log.info("录制启动成功: {}", resultMap); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("请求异常: {}", e.getMessage(), e); |
|
|
|
return false; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean stopRecording() { |
|
|
|
Boolean result = false; |
|
|
|
|
|
|
|
String url = String.format("%s%s?app=%s&stream=%s&type=%s&vhost=%s&secret=%s", |
|
|
|
zlmConfig.getApiUrl(), |
|
|
|
zlmConfig.getStopRecordUrl(), |
|
|
@ -69,20 +71,21 @@ public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
try { |
|
|
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); |
|
|
|
if (response.getStatusCode().is2xxSuccessful()) { |
|
|
|
Map<String, Object> result = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
log.info("录制停止成功: {}", result); |
|
|
|
Map<String, Object> resultMap = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
result = (Boolean) resultMap.get("status"); |
|
|
|
log.info("录制停止成功: {}", resultMap); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("请求异常: {}", e.getMessage(), e); |
|
|
|
return false; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String isRecording() { |
|
|
|
String result = null; |
|
|
|
public Boolean isRecording() { |
|
|
|
Boolean result = false; |
|
|
|
|
|
|
|
String url = String.format("%s%s?app=%s&stream=%s&type=%s&vhost=%s&secret=%s", |
|
|
|
zlmConfig.getApiUrl(), |
|
|
@ -97,13 +100,12 @@ public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); |
|
|
|
if (response.getStatusCode().is2xxSuccessful()) { |
|
|
|
Map<String, Object> resultMap = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
result = resultMap.get("status") + ""; |
|
|
|
result = (Boolean) resultMap.get("status"); |
|
|
|
log.info("获取录制状态成功: {}", resultMap); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("请求异常: {}", e.getMessage(), e); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
@ -111,6 +113,8 @@ public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean setRecordSpeed(Double speed) { |
|
|
|
Boolean result = false; |
|
|
|
|
|
|
|
String url = String.format("%s%s?app=%s&stream=%s&type=%s&vhost=%s&secret=%s&speed=%s", |
|
|
|
zlmConfig.getApiUrl(), |
|
|
|
zlmConfig.getRecordSpeedUrl(), |
|
|
@ -124,15 +128,16 @@ public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
try { |
|
|
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); |
|
|
|
if (response.getStatusCode().is2xxSuccessful()) { |
|
|
|
Map<String, Object> result = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
Map<String, Object> resultMap = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
result = (Boolean) resultMap.get("status"); |
|
|
|
log.info("设置录制速度成功: {}", result); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("请求异常: {}", e.getMessage(), e); |
|
|
|
return false; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -163,6 +168,8 @@ public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public Boolean seekRecordStamp(Integer stamp) { |
|
|
|
Boolean result = false; |
|
|
|
|
|
|
|
String url = String.format("%s%s?app=%s&stream=%s&vhost=%s&secret=%s&stamp=%s", |
|
|
|
zlmConfig.getApiUrl(), |
|
|
|
zlmConfig.getSeekRecordStampUrl(), |
|
|
@ -175,14 +182,15 @@ public class BusinessVideoServiceImpl implements BusinessVideoService { |
|
|
|
try { |
|
|
|
ResponseEntity<String> response = restTemplate.getForEntity(url, String.class); |
|
|
|
if (response.getStatusCode().is2xxSuccessful()) { |
|
|
|
Map<String, Object> result = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
log.info("设置录像流播放位置成功: {}", result); |
|
|
|
Map<String, Object> resultMap = objectMapper.readValue(response.getBody(), Map.class); |
|
|
|
result = (Boolean) resultMap.get("status"); |
|
|
|
log.info("设置录像流播放位置成功: {}", resultMap); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("请求异常: {}", e.getMessage(), e); |
|
|
|
return false; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|