diff --git a/components/SourceSelectionModal.tsx b/components/SourceSelectionModal.tsx index af43570..a5ced62 100644 --- a/components/SourceSelectionModal.tsx +++ b/components/SourceSelectionModal.tsx @@ -5,12 +5,24 @@ import useDetailStore from "@/stores/detailStore"; import usePlayerStore from "@/stores/playerStore"; export const SourceSelectionModal: React.FC = () => { - const { showSourceModal, setShowSourceModal } = usePlayerStore(); + const { showSourceModal, setShowSourceModal, loadVideo, currentEpisodeIndex, status } = usePlayerStore(); const { searchResults, detail, setDetail } = useDetailStore(); const onSelectSource = (index: number) => { + console.log("onSelectSource", index, searchResults[index].source, detail?.source); if (searchResults[index].source !== detail?.source) { - setDetail(searchResults[index]); + const newDetail = searchResults[index]; + setDetail(newDetail); + + // Reload the video with the new source, preserving current position + const currentPosition = status?.isLoaded ? status.positionMillis : undefined; + loadVideo({ + source: newDetail.source, + id: newDetail.id.toString(), + episodeIndex: currentEpisodeIndex, + title: newDetail.title, + position: currentPosition + }); } setShowSourceModal(false); }; diff --git a/stores/playerStore.ts b/stores/playerStore.ts index 3c94fa0..3e22a4b 100644 --- a/stores/playerStore.ts +++ b/stores/playerStore.ts @@ -254,7 +254,6 @@ const usePlayerStore = create((set, get) => ({ ...existingRecord, ...updates, }); - console.log("Play record saved") } },