Commit 04375d70 by zhangxingmin

push

parent 3b15b4e7
package com.yd.communication.api.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Data
@Component
@ConfigurationProperties(prefix = "aliyun.rtc")
public class AliyunRtcConfig {
private String accessKeyId;
private String accessKeySecret;
private String regionId = "cn-shanghai";
private String appId;
private String ossBucket;
private String ossEndpoint = "oss-cn-shanghai.aliyuncs.com";
}
\ No newline at end of file
//package com.yd.communication.api.config;
//
//import lombok.Data;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.stereotype.Component;
//
//@Data
//@Component
//@ConfigurationProperties(prefix = "aliyun.rtc")
//public class AliyunRtcConfig {
// private String accessKeyId;
// private String accessKeySecret;
// private String regionId = "cn-shanghai";
// private String appId;
// private String ossBucket;
// private String ossEndpoint = "oss-cn-shanghai.aliyuncs.com";
//}
\ No newline at end of file
package com.yd.communication.api.record;
import com.alibaba.fastjson2.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingRequest;
import com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.yd.communication.api.config.AliyunRtcConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
@Service
@Slf4j
public class AliyunRtcRecordService {
@Resource
private AliyunRtcConfig rtcConfig;
private IAcsClient getClient() {
DefaultProfile profile = DefaultProfile.getProfile(
rtcConfig.getRegionId(),
rtcConfig.getAccessKeyId(),
rtcConfig.getAccessKeySecret()
);
return new DefaultAcsClient(profile);
}
public String startRecording(String channelId) {
try {
IAcsClient client = getClient();
CommonRequest request = new CommonRequest();
request.setSysMethod(MethodType.POST);
request.setSysDomain("live.aliyuncs.com");
request.setSysVersion("2016-11-01");
request.setSysAction("StartRtcCloudRecording");
request.putQueryParameter("AppId", rtcConfig.getAppId());
request.putQueryParameter("ChannelId", channelId);
// 订阅所有用户(不传订阅参数则默认订阅所有)
request.putQueryParameter("RecordParams.RecordMode", "1");
request.putQueryParameter("StorageParams.StorageType", "1");
request.putQueryParameter("StorageParams.OSSParams.OSSEndpoint", rtcConfig.getOssEndpoint());
request.putQueryParameter("StorageParams.OSSParams.OSSBucket", rtcConfig.getOssBucket());
CommonResponse response = client.getCommonResponse(request);
String responseData = response.getData();
JSONObject jsonObject = JSONObject.parseObject(responseData);
JSONObject body = jsonObject.getJSONObject("Body");
String taskId = body.getString("TaskId");
if (taskId == null || taskId.isEmpty()) {
throw new RuntimeException("启动录制失败,未返回 TaskId,响应:" + responseData);
}
log.info("启动录制成功, TaskId: {}", taskId);
return taskId;
} catch (Exception e) {
log.error("启动录制失败", e);
throw new RuntimeException("启动云端录制失败: " + e.getMessage(), e);
}
}
public void stopRecording(String taskId) {
try {
IAcsClient client = getClient();
StopRtcCloudRecordingRequest request = new StopRtcCloudRecordingRequest();
request.setTaskId(taskId);
StopRtcCloudRecordingResponse response = client.getAcsResponse(request);
log.info("停止录制成功, TaskId: {}", taskId);
} catch (Exception e) {
log.error("停止录制失败", e);
throw new RuntimeException("停止云端录制失败: " + e.getMessage(), e);
}
}
/**
* 查询录制任务详情(文件信息)
* @param taskId
* @return
*/
public Map<String, String> queryRecordingInfo(String taskId) {
try {
IAcsClient client = getClient();
CommonRequest request = new CommonRequest();
request.setSysMethod(MethodType.POST);
request.setSysDomain("live.aliyuncs.com");
request.setSysVersion("2016-11-01");
request.setSysAction("DescribeCloudRecording");
request.putQueryParameter("TaskId", taskId);
CommonResponse response = client.getCommonResponse(request);
String responseData = response.getData();
log.info("查询录制信息响应: {}", responseData);
JSONObject jsonObject = JSONObject.parseObject(responseData);
JSONObject body = jsonObject.getJSONObject("Body");
if (body == null) {
return new HashMap<>();
}
Map<String, String> info = new HashMap<>();
// 根据实际返回字段解析,常见字段名
if (body.containsKey("FileUrl")) {
info.put("fileUrl", body.getString("FileUrl"));
} else if (body.containsKey("fileUrl")) {
info.put("fileUrl", body.getString("fileUrl"));
}
if (body.containsKey("Duration")) {
info.put("duration", body.getString("Duration"));
} else if (body.containsKey("duration")) {
info.put("duration", body.getString("duration"));
}
if (body.containsKey("FileSize")) {
info.put("size", body.getString("FileSize"));
} else if (body.containsKey("fileSize")) {
info.put("size", body.getString("fileSize"));
}
// 可能还有其他字段,如 RecordingStartTime, RecordingEndTime 等
return info;
} catch (Exception e) {
log.error("查询录制信息失败", e);
throw new RuntimeException("查询录制信息失败: " + e.getMessage(), e);
}
}
}
\ No newline at end of file
//package com.yd.communication.api.record;
//
//import com.alibaba.fastjson2.JSONObject;
//import com.aliyuncs.CommonRequest;
//import com.aliyuncs.CommonResponse;
//import com.aliyuncs.DefaultAcsClient;
//import com.aliyuncs.IAcsClient;
//import com.aliyuncs.http.MethodType;
//import com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingRequest;
//import com.aliyuncs.live.model.v20161101.StopRtcCloudRecordingResponse;
//import com.aliyuncs.profile.DefaultProfile;
//import com.yd.communication.api.config.AliyunRtcConfig;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Service;
//import javax.annotation.Resource;
//import java.util.HashMap;
//import java.util.Map;
//
//@Service
//@Slf4j
//public class AliyunRtcRecordService {
//
// @Resource
// private AliyunRtcConfig rtcConfig;
//
// private IAcsClient getClient() {
// DefaultProfile profile = DefaultProfile.getProfile(
// rtcConfig.getRegionId(),
// rtcConfig.getAccessKeyId(),
// rtcConfig.getAccessKeySecret()
// );
// return new DefaultAcsClient(profile);
// }
//
// public String startRecording(String channelId) {
// try {
// IAcsClient client = getClient();
// CommonRequest request = new CommonRequest();
// request.setSysMethod(MethodType.POST);
// request.setSysDomain("live.aliyuncs.com");
// request.setSysVersion("2016-11-01");
// request.setSysAction("StartRtcCloudRecording");
//
// request.putQueryParameter("AppId", rtcConfig.getAppId());
// request.putQueryParameter("ChannelId", channelId);
// // 订阅所有用户(不传订阅参数则默认订阅所有)
// request.putQueryParameter("RecordParams.RecordMode", "1");
// request.putQueryParameter("StorageParams.StorageType", "1");
// request.putQueryParameter("StorageParams.OSSParams.OSSEndpoint", rtcConfig.getOssEndpoint());
// request.putQueryParameter("StorageParams.OSSParams.OSSBucket", rtcConfig.getOssBucket());
//
// CommonResponse response = client.getCommonResponse(request);
// String responseData = response.getData();
// JSONObject jsonObject = JSONObject.parseObject(responseData);
// JSONObject body = jsonObject.getJSONObject("Body");
// String taskId = body.getString("TaskId");
// if (taskId == null || taskId.isEmpty()) {
// throw new RuntimeException("启动录制失败,未返回 TaskId,响应:" + responseData);
// }
// log.info("启动录制成功, TaskId: {}", taskId);
// return taskId;
// } catch (Exception e) {
// log.error("启动录制失败", e);
// throw new RuntimeException("启动云端录制失败: " + e.getMessage(), e);
// }
// }
//
// public void stopRecording(String taskId) {
// try {
// IAcsClient client = getClient();
// StopRtcCloudRecordingRequest request = new StopRtcCloudRecordingRequest();
// request.setTaskId(taskId);
// StopRtcCloudRecordingResponse response = client.getAcsResponse(request);
// log.info("停止录制成功, TaskId: {}", taskId);
// } catch (Exception e) {
// log.error("停止录制失败", e);
// throw new RuntimeException("停止云端录制失败: " + e.getMessage(), e);
// }
// }
//
// /**
// * 查询录制任务详情(文件信息)
// * @param taskId
// * @return
// */
// public Map<String, String> queryRecordingInfo(String taskId) {
// try {
// IAcsClient client = getClient();
// CommonRequest request = new CommonRequest();
// request.setSysMethod(MethodType.POST);
// request.setSysDomain("live.aliyuncs.com");
// request.setSysVersion("2016-11-01");
// request.setSysAction("DescribeCloudRecording");
// request.putQueryParameter("TaskId", taskId);
//
// CommonResponse response = client.getCommonResponse(request);
// String responseData = response.getData();
// log.info("查询录制信息响应: {}", responseData);
//
// JSONObject jsonObject = JSONObject.parseObject(responseData);
// JSONObject body = jsonObject.getJSONObject("Body");
// if (body == null) {
// return new HashMap<>();
// }
//
// Map<String, String> info = new HashMap<>();
// // 根据实际返回字段解析,常见字段名
// if (body.containsKey("FileUrl")) {
// info.put("fileUrl", body.getString("FileUrl"));
// } else if (body.containsKey("fileUrl")) {
// info.put("fileUrl", body.getString("fileUrl"));
// }
// if (body.containsKey("Duration")) {
// info.put("duration", body.getString("Duration"));
// } else if (body.containsKey("duration")) {
// info.put("duration", body.getString("duration"));
// }
// if (body.containsKey("FileSize")) {
// info.put("size", body.getString("FileSize"));
// } else if (body.containsKey("fileSize")) {
// info.put("size", body.getString("fileSize"));
// }
// // 可能还有其他字段,如 RecordingStartTime, RecordingEndTime 等
// return info;
// } catch (Exception e) {
// log.error("查询录制信息失败", e);
// throw new RuntimeException("查询录制信息失败: " + e.getMessage(), e);
// }
// }
//}
\ No newline at end of file
......@@ -74,19 +74,19 @@
<version>${project.version}</version>
</dependency>
<!-- 阿里云 Java SDK 核心库 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.6.3</version>
</dependency>
<!-- &lt;!&ndash; 阿里云 Java SDK 核心库 &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.aliyun</groupId>-->
<!-- <artifactId>aliyun-java-sdk-core</artifactId>-->
<!-- <version>4.6.3</version>-->
<!-- </dependency>-->
<!-- 阿里云视频直播 SDK(包含 RTC 云端录制 API) -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-live</artifactId>
<version>3.9.76</version>
</dependency>
<!-- &lt;!&ndash; 阿里云视频直播 SDK(包含 RTC 云端录制 API) &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>com.aliyun</groupId>-->
<!-- <artifactId>aliyun-java-sdk-live</artifactId>-->
<!-- <version>3.9.76</version>-->
<!-- </dependency>-->
</dependencies>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment