Browse Source

start at beginning when pressing next episode button

pull/497/head
mrjvs 2 years ago
parent
commit
b39ef2c31f
  1. 6
      src/components/player/atoms/NextEpisodeButton.tsx
  2. 8
      src/components/player/hooks/usePlayer.ts
  3. 23
      src/pages/PlayerView.tsx
  4. 8
      src/stores/player/slices/interface.ts

6
src/components/player/atoms/NextEpisodeButton.tsx

@ -50,6 +50,9 @@ export function NextEpisodeButton(props: { @@ -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: { @@ -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;

8
src/components/player/hooks/usePlayer.ts

@ -35,6 +35,12 @@ export function usePlayer() { @@ -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() { @@ -44,6 +50,8 @@ export function usePlayer() {
meta,
reset,
status,
shouldStartFromBeginning,
setShouldStartFromBeginning,
setMeta(m: PlayerMeta, newStatus?: PlayerStatus) {
setMeta(m, newStatus);
},

23
src/pages/PlayerView.tsx

@ -29,7 +29,14 @@ export function PlayerView() { @@ -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() { @@ -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(() => {

8
src/stores/player/slices/interface.ts

@ -22,6 +22,7 @@ export interface InterfaceSlice { @@ -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 { @@ -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) => ({ @@ -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;

Loading…
Cancel
Save