start at beginning when pressing next episode button

This commit is contained in:
mrjvs 2023-10-27 22:20:42 +02:00
parent 65d0218f81
commit b39ef2c31f
4 changed files with 41 additions and 4 deletions

View File

@ -50,6 +50,9 @@ export function NextEpisodeButton(props: {
const time = usePlayerStore((s) => s.progress.time);
const showingState = shouldShowNextEpisodeButton(time, duration);
const status = usePlayerStore((s) => s.status);
const setShouldStartFromBeginning = usePlayerStore(
(s) => s.setShouldStartFromBeginning
);
let show = false;
if (showingState === "always") show = true;
@ -69,9 +72,10 @@ export function NextEpisodeButton(props: {
if (!meta || !nextEp) return;
const metaCopy = { ...meta };
metaCopy.episode = nextEp;
setShouldStartFromBeginning(true);
setDirectMeta(metaCopy);
props.onChange?.(metaCopy);
}, [setDirectMeta, nextEp, meta, props]);
}, [setDirectMeta, nextEp, meta, props, setShouldStartFromBeginning]);
if (!meta?.episode || !nextEp) return null;
if (metaType !== "show") return null;

View File

@ -35,6 +35,12 @@ export function usePlayer() {
const setSource = usePlayerStore((s) => s.setSource);
const setSourceId = usePlayerStore((s) => s.setSourceId);
const status = usePlayerStore((s) => s.status);
const shouldStartFromBeginning = usePlayerStore(
(s) => s.interface.shouldStartFromBeginning
);
const setShouldStartFromBeginning = usePlayerStore(
(s) => s.setShouldStartFromBeginning
);
const reset = usePlayerStore((s) => s.reset);
const meta = usePlayerStore((s) => s.meta);
const { init } = useInitializePlayer();
@ -44,6 +50,8 @@ export function usePlayer() {
meta,
reset,
status,
shouldStartFromBeginning,
setShouldStartFromBeginning,
setMeta(m: PlayerMeta, newStatus?: PlayerStatus) {
setMeta(m, newStatus);
},

View File

@ -29,7 +29,14 @@ export function PlayerView() {
sourceOrder: ScrapingItems[];
} | null>(null);
const [startAtParam] = useQueryParam("t");
const { status, playMedia, reset, setScrapeNotFound } = usePlayer();
const {
status,
playMedia,
reset,
setScrapeNotFound,
shouldStartFromBeginning,
setShouldStartFromBeginning,
} = usePlayer();
const { setPlayerMeta, scrapeMedia } = usePlayerMeta();
const backUrl = useLastNonPlayerLink();
const { disable } = useCaptions();
@ -61,9 +68,19 @@ export function PlayerView() {
let startAt: number | undefined;
if (startAtParam) startAt = parseTimestamp(startAtParam) ?? undefined;
playMedia(convertRunoutputToSource(out), out.sourceId, startAt);
playMedia(
convertRunoutputToSource(out),
out.sourceId,
shouldStartFromBeginning ? 0 : startAt
);
setShouldStartFromBeginning(false);
},
[playMedia, startAtParam]
[
playMedia,
startAtParam,
shouldStartFromBeginning,
setShouldStartFromBeginning,
]
);
useEffectOnce(() => {

View File

@ -22,6 +22,7 @@ export interface InterfaceSlice {
canAirplay: boolean;
isCasting: boolean;
hideNextEpisodeBtn: boolean;
shouldStartFromBeginning: boolean;
volumeChangedWithKeybind: boolean; // has the volume recently been adjusted with the up/down arrows recently?
volumeChangedWithKeybindDebounce: NodeJS.Timeout | null; // debounce for the duration of the "volume changed thingamajig"
@ -38,6 +39,7 @@ export interface InterfaceSlice {
setHasOpenOverlay(state: boolean): void;
setLastVolume(state: number): void;
hideNextEpisodeButton(): void;
setShouldStartFromBeginning(val: boolean): void;
}
export const createInterfaceSlice: MakeSlice<InterfaceSlice> = (set, get) => ({
@ -56,8 +58,14 @@ export const createInterfaceSlice: MakeSlice<InterfaceSlice> = (set, get) => ({
timeFormat: VideoPlayerTimeFormat.REGULAR,
canAirplay: false,
hideNextEpisodeBtn: false,
shouldStartFromBeginning: false,
},
setShouldStartFromBeginning(val) {
set((s) => {
s.interface.shouldStartFromBeginning = val;
});
},
setLastVolume(state) {
set((s) => {
s.interface.lastVolume = state;