fix(playback): 优化播放逻辑,移除冗余SEEK指令,确保时间戳处理无毫秒

This commit is contained in:
xudan 2025-10-30 10:36:43 +08:00
parent 149fcb5a37
commit fa8f6aa063
2 changed files with 21 additions and 18 deletions

View File

@ -151,9 +151,8 @@ export function usePlaybackWebSocket(
};
const play = () => {
// 双重保险在播放前强制发送一次SEEK指令确保后端从正确的时间点开始。
// 这可以防止因后端状态不同步或时序问题导致的播放位置错乱。
sendCommand(`SEEK:${currentTime.value}`);
// [修复] 移除冗余的 SEEK 指令,避免与后端的时序问题导致日期跳转。
// SEEK 操作应仅由用户显式触发(如拖动滑块或更改日期)。
sendCommand('PLAY');
isPlaying.value = true;
};

View File

@ -107,6 +107,7 @@ let doorMockTick = 0;
const leftSiderEl = shallowRef<HTMLElement>();
const isPlaybackControllerVisible = ref<boolean>(true);
const selectedDate = ref<Dayjs>();
const isSceneLoading = ref(false);
const playback = usePlaybackWebSocket(editor, async () => {
// []
@ -129,9 +130,14 @@ watch(mode, async (newMode) => {
watch(playback.sceneJson, async (newJson) => {
if (newJson) {
await editor.value?.load(newJson);
// [] onFirstAmrData
// await editor.value?.initRobots();
isSceneLoading.value = true;
try {
await editor.value?.load(newJson);
// [] onFirstAmrData
// await editor.value?.initRobots();
} finally {
isSceneLoading.value = false;
}
}
});
@ -174,9 +180,11 @@ onUnmounted(() => {
});
watch(selectedDate, (date) => {
if (isSceneLoading.value) return;
if (date) {
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
playback.totalDuration.value = 24 * 60 * 60 * 1000;
// 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();
//
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
@ -456,10 +458,12 @@ onMounted(async () => {
} else {
console.log('[回放模式] 初始化回放模式');
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;
playback.seek(debugDate.valueOf());
// seek
// []
playback.seek(Math.floor(debugDate.valueOf() / 1000) * 1000);
}
// [] onFirstAmrData