diff --git a/components/player/VideoPlayer.tsx b/components/player/VideoPlayer.tsx index 322e374..3ba4aa2 100644 --- a/components/player/VideoPlayer.tsx +++ b/components/player/VideoPlayer.tsx @@ -17,18 +17,30 @@ interface VideoPlayerProps { export function VideoPlayer({ playUrl, videoId, currentEpisode, onBack }: VideoPlayerProps) { const [videoError, setVideoError] = useState(''); + // Use reactive hook to subscribe to history updates + // This ensures the component re-renders when history is hydrated from localStorage + const viewingHistory = useHistoryStore(state => state.viewingHistory); const searchParams = useSearchParams(); const { addToHistory } = useHistoryStore(); - + // Get video metadata from URL params const source = searchParams.get('source') || ''; const title = searchParams.get('title') || '未知视频'; - + // Get saved progress for this video const getSavedProgress = () => { if (!videoId) return 0; - const savedTime = localStorage.getItem(`video_progress_${videoId}_${currentEpisode}`); - return savedTime ? parseFloat(savedTime) : 0; + + // Directly check HistoryStore for progress + // This is the single source of truth for playback resumption + const historyItem = viewingHistory.find(item => + // Loose match for videoId (string vs number) + item.videoId.toString() === videoId?.toString() && + item.source === source && + item.episodeIndex === currentEpisode + ); + + return historyItem ? historyItem.playbackPosition : 0; }; // Handle time updates and save progress @@ -74,7 +86,7 @@ export function VideoPlayer({ playUrl, videoId, currentEpisode, onBack }: VideoP {videoError ? (
-
播放失败

{videoError}

- -