浏览代码

fix: 修复回放一直重播问题

xieyonghong 3 年之前
父节点
当前提交
0f339e72b3
共有 2 个文件被更改,包括 25 次插入14 次删除
  1. 6 13
      src/pages/media/Device/Playback/index.tsx
  2. 19 1
      src/pages/media/Device/Playback/timeLine.tsx

+ 6 - 13
src/pages/media/Device/Playback/index.tsx

@@ -298,24 +298,17 @@ export default () => {
                           <a
                             onClick={() => {
                               if (playStatus === 0 || _startTime !== playNowTime.current) {
-                                playNowTime.current = _startTime;
-                                if (type === 'local' && deviceId && channelId) {
-                                  setUrl(
-                                    service.playbackLocal(
-                                      deviceId,
-                                      channelId,
-                                      'mp4',
-                                      moment(item.startTime).format('YYYY-MM-DD HH:mm:ss'),
-                                      moment(item.endTime).format('YYYY-MM-DD HH:mm:ss'),
-                                    ),
-                                  );
-                                } else {
-                                  setUrl(service.playbackStart(item.id));
+                                if (playTimeNode.current) {
+                                  playTimeNode.current.playByStartTime(_startTime);
                                 }
                               } else if (playStatus == 1 && _startTime === playNowTime.current) {
                                 if (player.current.getVueInstance) {
                                   player.current.getVueInstance().pause();
                                 }
+                              } else if (playStatus == 2 && _startTime === playNowTime.current) {
+                                if (player.current.getVueInstance) {
+                                  player.current.getVueInstance().play();
+                                }
                               }
                             }}
                           >

+ 19 - 1
src/pages/media/Device/Playback/timeLine.tsx

@@ -71,6 +71,23 @@ const Progress = forwardRef((props: Props, ref) => {
     });
   };
 
+  const playByStartTime = useCallback(
+    (time) => {
+      const playNow = props.data.find((item) => {
+        const startTime = item.startTime || item.mediaStartTime;
+        return startTime === time;
+      });
+
+      if (playNow) {
+        const startTime = playNow.startTime || playNow.mediaStartTime;
+        const endTime = playNow.endTime || playNow.mediaEndTime;
+        const deviceId = props.type === 'local' ? playNow.deviceId : playNow.id;
+        onChange(startTime, endTime, deviceId, playNow.channelId);
+      }
+    },
+    [props.type, props.data],
+  );
+
   const onNextPlay = useCallback(() => {
     if (playTime) {
       // 查找下一个视频
@@ -87,7 +104,7 @@ const Progress = forwardRef((props: Props, ref) => {
         onChange(startTime, endTime, deviceId, nextPlay.channelId);
       }
     }
-  }, [props.type, playTime]);
+  }, [props.type, playTime, props.data]);
 
   useEffect(() => {
     const { data, localToServer, type } = props;
@@ -161,6 +178,7 @@ const Progress = forwardRef((props: Props, ref) => {
 
   useImperativeHandle(ref, () => ({
     onNextPlay,
+    playByStartTime,
   }));
 
   return (