mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-05-21 17:27:28 +08:00
fix: reload video with new source while preserving playback position
This commit is contained in:
@@ -5,12 +5,24 @@ import useDetailStore from "@/stores/detailStore";
|
|||||||
import usePlayerStore from "@/stores/playerStore";
|
import usePlayerStore from "@/stores/playerStore";
|
||||||
|
|
||||||
export const SourceSelectionModal: React.FC = () => {
|
export const SourceSelectionModal: React.FC = () => {
|
||||||
const { showSourceModal, setShowSourceModal } = usePlayerStore();
|
const { showSourceModal, setShowSourceModal, loadVideo, currentEpisodeIndex, status } = usePlayerStore();
|
||||||
const { searchResults, detail, setDetail } = useDetailStore();
|
const { searchResults, detail, setDetail } = useDetailStore();
|
||||||
|
|
||||||
const onSelectSource = (index: number) => {
|
const onSelectSource = (index: number) => {
|
||||||
|
console.log("onSelectSource", index, searchResults[index].source, detail?.source);
|
||||||
if (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);
|
setShowSourceModal(false);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -254,7 +254,6 @@ const usePlayerStore = create<PlayerState>((set, get) => ({
|
|||||||
...existingRecord,
|
...existingRecord,
|
||||||
...updates,
|
...updates,
|
||||||
});
|
});
|
||||||
console.log("Play record saved")
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user