mirror of
https://github.com/movie-web/native-app.git
synced 2025-09-13 14:53:24 +00:00
feat: jump to last watched position
This commit is contained in:
@@ -75,7 +75,8 @@ export const VideoPlayer = () => {
|
|||||||
const setMeta = usePlayerStore((state) => state.setMeta);
|
const setMeta = usePlayerStore((state) => state.setMeta);
|
||||||
|
|
||||||
const { gestureControls, autoPlay } = usePlayerSettingsStore();
|
const { gestureControls, autoPlay } = usePlayerSettingsStore();
|
||||||
const { updateWatchHistory, removeFromWatchHistory } = useWatchHistoryStore();
|
const { updateWatchHistory, removeFromWatchHistory, getWatchHistorItem } =
|
||||||
|
useWatchHistoryStore();
|
||||||
|
|
||||||
const updateResizeMode = (newMode: ResizeMode) => {
|
const updateResizeMode = (newMode: ResizeMode) => {
|
||||||
setResizeMode(newMode);
|
setResizeMode(newMode);
|
||||||
@@ -238,14 +239,14 @@ export const VideoPlayer = () => {
|
|||||||
setHasStartedPlaying(true);
|
setHasStartedPlaying(true);
|
||||||
if (videoRef) {
|
if (videoRef) {
|
||||||
void videoRef.setRateAsync(currentSpeed, true);
|
void videoRef.setRateAsync(currentSpeed, true);
|
||||||
|
|
||||||
if (meta) {
|
if (meta) {
|
||||||
const item = convertMetaToItemData(meta);
|
const media = convertMetaToScrapeMedia(meta);
|
||||||
const scrapeMedia = convertMetaToScrapeMedia(meta);
|
const watchHistoryItem = getWatchHistorItem(media);
|
||||||
updateWatchHistory(
|
|
||||||
item,
|
if (watchHistoryItem) {
|
||||||
scrapeMedia,
|
void videoRef.setPositionAsync(watchHistoryItem.positionMillis);
|
||||||
videoRef.props.positionMillis ?? 0,
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -1,5 +1,9 @@
|
|||||||
import type { ScrapeMedia } from "@movie-web/provider-utils";
|
import type { ScrapeMedia } from "@movie-web/provider-utils";
|
||||||
import { fetchMediaDetails, fetchSeasonDetails, getMediaPoster } from "@movie-web/tmdb";
|
import {
|
||||||
|
fetchMediaDetails,
|
||||||
|
fetchSeasonDetails,
|
||||||
|
getMediaPoster,
|
||||||
|
} from "@movie-web/tmdb";
|
||||||
|
|
||||||
import type { ItemData } from "~/components/item/item";
|
import type { ItemData } from "~/components/item/item";
|
||||||
import type { PlayerMeta } from "~/stores/player/slices/video";
|
import type { PlayerMeta } from "~/stores/player/slices/video";
|
||||||
|
@@ -141,6 +141,7 @@ interface WatchHistoryItem {
|
|||||||
|
|
||||||
interface WatchHistoryStoreState {
|
interface WatchHistoryStoreState {
|
||||||
watchHistory: WatchHistoryItem[];
|
watchHistory: WatchHistoryItem[];
|
||||||
|
getWatchHistorItem: (media: ScrapeMedia) => WatchHistoryItem | undefined;
|
||||||
setWatchHistory: (watchHistory: WatchHistoryItem[]) => void;
|
setWatchHistory: (watchHistory: WatchHistoryItem[]) => void;
|
||||||
updateWatchHistory: (
|
updateWatchHistory: (
|
||||||
item: ItemData,
|
item: ItemData,
|
||||||
@@ -155,8 +156,23 @@ export const useWatchHistoryStore = create<
|
|||||||
[["zustand/persist", WatchHistoryStoreState]]
|
[["zustand/persist", WatchHistoryStoreState]]
|
||||||
>(
|
>(
|
||||||
persist(
|
persist(
|
||||||
(set) => ({
|
(set, get) => ({
|
||||||
watchHistory: [],
|
watchHistory: [],
|
||||||
|
getWatchHistorItem: (media: ScrapeMedia) =>
|
||||||
|
get().watchHistory.find((historyItem) => {
|
||||||
|
if (historyItem.media.type === "movie" && media.type === "movie") {
|
||||||
|
return historyItem.media.tmdbId === media.tmdbId;
|
||||||
|
} else if (
|
||||||
|
historyItem.media.type === "show" &&
|
||||||
|
media.type === "show"
|
||||||
|
) {
|
||||||
|
return (
|
||||||
|
historyItem.media.tmdbId === media.tmdbId &&
|
||||||
|
historyItem.media.season === media.season &&
|
||||||
|
historyItem.media.episode === media.episode
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}),
|
||||||
setWatchHistory: (watchHistory: WatchHistoryItem[]) =>
|
setWatchHistory: (watchHistory: WatchHistoryItem[]) =>
|
||||||
set({ watchHistory }),
|
set({ watchHistory }),
|
||||||
updateWatchHistory: (
|
updateWatchHistory: (
|
||||||
|
Reference in New Issue
Block a user