Eric 2 years ago
parent
commit
3d5d660726

+ 3 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ImLiveBroadcastRoomServiceImpl.java

@@ -670,7 +670,9 @@ public class ImLiveBroadcastRoomServiceImpl extends ServiceImpl<ImLiveBroadcastR
 
                 List<String> collect = imLiveRoomVideoService.lambdaQuery()
                         .eq(ImLiveRoomVideo::getRoomUid, roomUid).list().stream()
-                        .map(ImLiveRoomVideo::getRecordId).distinct().collect(Collectors.toList());
+                        .map(ImLiveRoomVideo::getRecordId)
+                        .filter(StringUtils::isNotEmpty)
+                        .distinct().collect(Collectors.toList());
 
                 for (String taskId : collect) {
                     // 删除录制任务

+ 4 - 1
mec-im/src/main/java/com/ym/controller/UserController.java

@@ -115,7 +115,7 @@ public class UserController {
         // 推流事件通知
         if (event.getEventType() == 1) {
             // 自动开启录制
-            // liveRoomService.strartTencentLiveVideoRecord(event.getStreamId());
+            // liveRoomService.startTencentLiveVideoRecord(event.getStreamId());
         }
 
         return TencentData.StreamEventCallbackResult.builder().code(0).build();
@@ -131,6 +131,9 @@ public class UserController {
 
         log.info("taskId={}, url={}", event.getTaskId(), event.getVideoUrl());
 
+        // 生成直播录制信息
+        liveRoomService.createLiveRoomVideoRecord(event);
+
         return TencentData.StreamEventCallbackResult.builder().code(0).build();
     }
 

+ 35 - 5
mec-im/src/main/java/com/ym/service/Impl/LiveRoomServiceImpl.java

@@ -8,6 +8,7 @@ import com.microsvc.toolkit.middleware.live.impl.TencentCloudLivePlugin;
 import com.microsvc.toolkit.middleware.live.message.RTCRequest;
 import com.microsvc.toolkit.middleware.live.message.RTCRoom;
 import com.ym.http.HttpHelper;
+import com.ym.mec.biz.dal.dto.TencentData;
 import com.ym.mec.biz.dal.entity.ImLiveRoomVideo;
 import com.ym.mec.biz.service.ImLiveRoomVideoService;
 import com.ym.mec.common.entity.ImRoomMessage;
@@ -333,16 +334,15 @@ public class LiveRoomServiceImpl implements LiveRoomService {
      * @param streamId 推流Id
      */
     @Override
-    public void strartTencentLiveVideoRecord(String streamId) {
-
-        // 直播间ROOM_UID
-        String roomId = streamId.split("_")[0];
+    public void startTencentLiveVideoRecord(String streamId) {
 
+        DateTime now = DateTime.now();
         // 创建直播录制
         RTCRequest.RecordStart recordStart = RTCRequest.RecordStart.builder()
                 .streamName(streamId)
                 .extra("")
-                .endTime(DateTime.now().plusHours(23).getMillis() / 1000)
+                .startTime(now.getMillis())
+                .endTime(now.plusDays(1).getMillis())
                 .build();
         // 创建录制任务失败,重试3次后,发送IM消息通知主播老师
         int maxRetry = 0;
@@ -365,7 +365,11 @@ public class LiveRoomServiceImpl implements LiveRoomService {
             }
         } while (maxRetry++ < 3);
 
+        log.info("startTencentLiveVideoRecord taskId={}", taskId);
         // 生成录制记录
+        // 直播间ROOM_UID
+        String roomId = streamId.split("_")[0];
+
         ImLiveRoomVideo video = imLiveRoomVideoService.getOne(new QueryWrapper<ImLiveRoomVideo>()
                 .eq("room_uid_", roomId)
                 .eq("record_id_", taskId)
@@ -403,4 +407,30 @@ public class LiveRoomServiceImpl implements LiveRoomService {
         } while (maxRetry++ < 3);
 
     }
+
+    /**
+     * 生成直播录制信息
+     *
+     * @param event TencentData.CallbackSteamRecordEvent
+     */
+    @Override
+    public void createLiveRoomVideoRecord(TencentData.CallbackSteamRecordEvent event) {
+
+        // 直播间ROOM_UID
+        String roomId = event.getStreamId().split("_")[0];
+
+        //云端录制文件地址
+        String fileUrl = storagePluginContext.getPublicUrl(event.getVideoUrl(),"live-rewind");
+
+        // 录制开始时间
+        long startTime =  (event.getEndTime() - event.getDuration()) * 1000L;
+        //保存切片
+        ImLiveRoomVideo imLiveRoomVideo = initImLiveRoomVideo(roomId, event.getTaskId(), DateTime.now().toDate());
+        imLiveRoomVideo.setStartTime(new DateTime(startTime).toDate());
+        imLiveRoomVideo.setEndTime(new DateTime(event.getEndTime() * 1000L).toDate());
+        imLiveRoomVideo.setUrl(fileUrl);
+        imLiveRoomVideo.setType(2);
+
+        imLiveRoomVideoService.save(imLiveRoomVideo);
+    }
 }

+ 8 - 1
mec-im/src/main/java/com/ym/service/LiveRoomService.java

@@ -1,5 +1,6 @@
 package com.ym.service;
 
+import com.ym.mec.biz.dal.dto.TencentData;
 import com.ym.mec.common.entity.ImRoomMessage;
 import com.ym.pojo.IMApiResultInfo;
 import com.ym.pojo.RecordNotify;
@@ -67,11 +68,17 @@ public interface LiveRoomService {
      * 开始tencent云直播录制记录
      * @param streamId 推流Id
      */
-    void strartTencentLiveVideoRecord(String streamId);
+    void startTencentLiveVideoRecord(String streamId);
 
     /**
      * 关闭tencent云直播录制记录
      * @param streamId 推流Id
      */
     void stopTencentLiveVideoRecord(String streamId);
+
+    /**
+     * 生成直播录制信息
+     * @param event TencentData.CallbackSteamRecordEvent
+     */
+    void createLiveRoomVideoRecord(TencentData.CallbackSteamRecordEvent event);
 }