fix(playback): 优化播放逻辑,移除冗余SEEK指令,确保时间戳处理无毫秒
This commit is contained in:
parent
149fcb5a37
commit
fa8f6aa063
@ -151,9 +151,8 @@ export function usePlaybackWebSocket(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const play = () => {
|
const play = () => {
|
||||||
// 双重保险:在播放前,强制发送一次SEEK指令,确保后端从正确的时间点开始。
|
// [修复] 移除冗余的 SEEK 指令,避免与后端的时序问题导致日期跳转。
|
||||||
// 这可以防止因后端状态不同步或时序问题导致的播放位置错乱。
|
// SEEK 操作应仅由用户显式触发(如拖动滑块或更改日期)。
|
||||||
sendCommand(`SEEK:${currentTime.value}`);
|
|
||||||
sendCommand('PLAY');
|
sendCommand('PLAY');
|
||||||
isPlaying.value = true;
|
isPlaying.value = true;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -107,6 +107,7 @@ let doorMockTick = 0;
|
|||||||
const leftSiderEl = shallowRef<HTMLElement>();
|
const leftSiderEl = shallowRef<HTMLElement>();
|
||||||
const isPlaybackControllerVisible = ref<boolean>(true);
|
const isPlaybackControllerVisible = ref<boolean>(true);
|
||||||
const selectedDate = ref<Dayjs>();
|
const selectedDate = ref<Dayjs>();
|
||||||
|
const isSceneLoading = ref(false);
|
||||||
|
|
||||||
const playback = usePlaybackWebSocket(editor, async () => {
|
const playback = usePlaybackWebSocket(editor, async () => {
|
||||||
// [关键修复] 只有在收到第一帧机器人数据后才初始化机器人图元
|
// [关键修复] 只有在收到第一帧机器人数据后才初始化机器人图元
|
||||||
@ -129,9 +130,14 @@ watch(mode, async (newMode) => {
|
|||||||
|
|
||||||
watch(playback.sceneJson, async (newJson) => {
|
watch(playback.sceneJson, async (newJson) => {
|
||||||
if (newJson) {
|
if (newJson) {
|
||||||
await editor.value?.load(newJson);
|
isSceneLoading.value = true;
|
||||||
// [移除] 不再需要在这里初始化机器人,交由 onFirstAmrData 回调处理
|
try {
|
||||||
// await editor.value?.initRobots();
|
await editor.value?.load(newJson);
|
||||||
|
// [移除] 不再需要在这里初始化机器人,交由 onFirstAmrData 回调处理
|
||||||
|
// await editor.value?.initRobots();
|
||||||
|
} finally {
|
||||||
|
isSceneLoading.value = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -174,9 +180,11 @@ onUnmounted(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
watch(selectedDate, (date) => {
|
watch(selectedDate, (date) => {
|
||||||
|
if (isSceneLoading.value) return;
|
||||||
if (date) {
|
if (date) {
|
||||||
const startOfDayTimestamp = date.startOf('day').valueOf();
|
const startOfDayTimestamp = date.startOf('day').valueOf();
|
||||||
playback.seek(startOfDayTimestamp);
|
// [修复] 确保传入的时间戳没有毫秒
|
||||||
|
playback.seek(Math.floor(startOfDayTimestamp / 1000) * 1000);
|
||||||
// The total duration is now relative to the start of the day
|
// The total duration is now relative to the start of the day
|
||||||
playback.totalDuration.value = 24 * 60 * 60 * 1000;
|
playback.totalDuration.value = 24 * 60 * 60 * 1000;
|
||||||
// Set current time to the beginning of the selected day for the slider
|
// Set current time to the beginning of the selected day for the slider
|
||||||
@ -189,7 +197,8 @@ const handleSeek = (relativeTime: number) => {
|
|||||||
const absoluteTimestamp = relativeTime + selectedDate.value.startOf('day').valueOf();
|
const absoluteTimestamp = relativeTime + selectedDate.value.startOf('day').valueOf();
|
||||||
// 乐观更新,立即将前端时间状态同步到用户选择的时间点
|
// 乐观更新,立即将前端时间状态同步到用户选择的时间点
|
||||||
playback.currentTime.value = absoluteTimestamp;
|
playback.currentTime.value = absoluteTimestamp;
|
||||||
playback.seek(absoluteTimestamp);
|
// [修复] 确保传入的时间戳没有毫秒
|
||||||
|
playback.seek(Math.floor(absoluteTimestamp / 1000) * 1000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -207,13 +216,6 @@ watch(playback.currentTime, (newTimestamp) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(playback.sceneJson, async (newJson) => {
|
|
||||||
if (newJson) {
|
|
||||||
await editor.value?.load(newJson);
|
|
||||||
// [移除] 不再需要在这里初始化机器人,交由 onFirstAmrData 回调处理
|
|
||||||
// await editor.value?.initRobots();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
@ -456,10 +458,12 @@ onMounted(async () => {
|
|||||||
} else {
|
} else {
|
||||||
console.log('[回放模式] 初始化回放模式');
|
console.log('[回放模式] 初始化回放模式');
|
||||||
playback.connect(props.sid);
|
playback.connect(props.sid);
|
||||||
// [调试代码] 自动设置回放日期和时间
|
// [修复] 恢复调试用的日期设置,并更新为指定时间,以确保回放组件可见
|
||||||
const debugDate = dayjs('2025-09-28 09:00:00');
|
const debugDate = dayjs('2025-10-29 14:50:00');
|
||||||
selectedDate.value = debugDate;
|
selectedDate.value = debugDate;
|
||||||
playback.seek(debugDate.valueOf());
|
// 直接 seek 到指定的时间点,而不是当天的开始
|
||||||
|
// [修复] 确保传入的时间戳没有毫秒
|
||||||
|
playback.seek(Math.floor(debugDate.valueOf() / 1000) * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [移除] 不再需要在这里初始化机器人,交由 onFirstAmrData 回调处理
|
// [移除] 不再需要在这里初始化机器人,交由 onFirstAmrData 回调处理
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user