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

View File

@ -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