mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-21 14:47:41 +01:00
fix popout math and fix seeking not seeking
Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com> Co-authored-by: William Oldham <wegg7250@gmail.com>
This commit is contained in:
parent
403142783c
commit
0105c4f6b2
5 changed files with 29 additions and 18 deletions
|
@ -9,6 +9,7 @@ interface BackdropActionProps {
|
||||||
onBackdropChange?: (showing: boolean) => void;
|
onBackdropChange?: (showing: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO tap on mobile should remove backdrop instead of pausing
|
||||||
export function BackdropAction(props: BackdropActionProps) {
|
export function BackdropAction(props: BackdropActionProps) {
|
||||||
const descriptor = useVideoPlayerDescriptor();
|
const descriptor = useVideoPlayerDescriptor();
|
||||||
const controls = useControls(descriptor);
|
const controls = useControls(descriptor);
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
makePercentageString,
|
makePercentageString,
|
||||||
useProgressBar,
|
useProgressBar,
|
||||||
} from "@/hooks/useProgressBar";
|
} from "@/hooks/useProgressBar";
|
||||||
|
import { getPlayerState } from "@/video/state/cache";
|
||||||
import { useVideoPlayerDescriptor } from "@/video/state/hooks";
|
import { useVideoPlayerDescriptor } from "@/video/state/hooks";
|
||||||
import { useControls } from "@/video/state/logic/controls";
|
import { useControls } from "@/video/state/logic/controls";
|
||||||
import { useProgress } from "@/video/state/logic/progress";
|
import { useProgress } from "@/video/state/logic/progress";
|
||||||
|
@ -34,9 +35,12 @@ export function ProgressAction() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (dragging) {
|
if (dragging) {
|
||||||
controls.setDraggingTime(videoTime.duration * (dragPercentage / 100));
|
const state = getPlayerState(descriptor);
|
||||||
|
controls.setDraggingTime(
|
||||||
|
state.progress.duration * (dragPercentage / 100)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, [videoTime, dragging, dragPercentage, controls]);
|
}, [descriptor, dragging, dragPercentage, controls]);
|
||||||
|
|
||||||
let watchProgress = makePercentageString(
|
let watchProgress = makePercentageString(
|
||||||
makePercentage((videoTime.time / videoTime.duration) * 100)
|
makePercentage((videoTime.time / videoTime.duration) * 100)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { EpisodeSelectionPopout } from "@/video/components/popouts/EpisodeSelect
|
||||||
import { useVideoPlayerDescriptor } from "@/video/state/hooks";
|
import { useVideoPlayerDescriptor } from "@/video/state/hooks";
|
||||||
import { useControls } from "@/video/state/logic/controls";
|
import { useControls } from "@/video/state/logic/controls";
|
||||||
import { useInterface } from "@/video/state/logic/interface";
|
import { useInterface } from "@/video/state/logic/interface";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
|
||||||
import "./Popouts.css";
|
import "./Popouts.css";
|
||||||
|
|
||||||
|
@ -20,8 +20,9 @@ function ShowPopout(props: { popoutId: string | null }) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO improve anti offscreen math
|
// TODO bug: first load ref is null
|
||||||
export function PopoutProviderAction() {
|
export function PopoutProviderAction() {
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
const descriptor = useVideoPlayerDescriptor();
|
const descriptor = useVideoPlayerDescriptor();
|
||||||
const videoInterface = useInterface(descriptor);
|
const videoInterface = useInterface(descriptor);
|
||||||
const controls = useControls(descriptor);
|
const controls = useControls(descriptor);
|
||||||
|
@ -32,19 +33,23 @@ export function PopoutProviderAction() {
|
||||||
}, [controls]);
|
}, [controls]);
|
||||||
|
|
||||||
const distanceFromRight = useMemo(() => {
|
const distanceFromRight = useMemo(() => {
|
||||||
return videoInterface.popoutBounds
|
if (!videoInterface.popoutBounds) return 30;
|
||||||
? `${Math.max(
|
|
||||||
window.innerWidth -
|
const buttonCenter =
|
||||||
videoInterface.popoutBounds.right -
|
videoInterface.popoutBounds.left + videoInterface.popoutBounds.width / 2;
|
||||||
videoInterface.popoutBounds.width / 2,
|
|
||||||
30
|
return Math.max(
|
||||||
)}px`
|
window.innerWidth -
|
||||||
: "30px";
|
buttonCenter -
|
||||||
|
(ref.current?.getBoundingClientRect().width ?? 0) / 2,
|
||||||
|
30
|
||||||
|
);
|
||||||
}, [videoInterface.popoutBounds]);
|
}, [videoInterface.popoutBounds]);
|
||||||
|
|
||||||
const distanceFromBottom = useMemo(() => {
|
const distanceFromBottom = useMemo(() => {
|
||||||
return videoInterface.popoutBounds
|
return videoInterface.popoutBounds
|
||||||
? `${videoInterface.popoutBounds.height + 30}px`
|
? videoInterface.popoutBounds.height + 30
|
||||||
: "30px";
|
: 30;
|
||||||
}, [videoInterface.popoutBounds]);
|
}, [videoInterface.popoutBounds]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -56,10 +61,11 @@ export function PopoutProviderAction() {
|
||||||
<div className="popout-wrapper pointer-events-auto absolute inset-0">
|
<div className="popout-wrapper pointer-events-auto absolute inset-0">
|
||||||
<div onClick={handleClick} className="absolute inset-0" />
|
<div onClick={handleClick} className="absolute inset-0" />
|
||||||
<div
|
<div
|
||||||
|
ref={ref}
|
||||||
className="absolute z-10 grid h-[500px] w-80 grid-rows-[auto,minmax(0,1fr)] overflow-hidden rounded-lg bg-ash-200"
|
className="absolute z-10 grid h-[500px] w-80 grid-rows-[auto,minmax(0,1fr)] overflow-hidden rounded-lg bg-ash-200"
|
||||||
style={{
|
style={{
|
||||||
right: distanceFromRight,
|
right: `${distanceFromRight}px`,
|
||||||
bottom: distanceFromBottom,
|
bottom: `${distanceFromBottom}px`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ShowPopout popoutId={videoInterface.popout} />
|
<ShowPopout popoutId={videoInterface.popout} />
|
||||||
|
|
|
@ -25,6 +25,7 @@ function initPlayer(): VideoPlayerState {
|
||||||
time: 0,
|
time: 0,
|
||||||
duration: 0,
|
duration: 0,
|
||||||
buffered: 0,
|
buffered: 0,
|
||||||
|
draggingTime: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
meta: null,
|
meta: null,
|
||||||
|
|
|
@ -99,8 +99,7 @@ export function createVideoStateProvider(
|
||||||
},
|
},
|
||||||
setSeeking(active) {
|
setSeeking(active) {
|
||||||
state.mediaPlaying.isSeeking = active;
|
state.mediaPlaying.isSeeking = active;
|
||||||
updateInterface(descriptor, state);
|
updateMediaPlaying(descriptor, state);
|
||||||
// TODO is seeking is bugged when buffering (recursive seeking as well)
|
|
||||||
|
|
||||||
// if it was playing when starting to seek, play again
|
// if it was playing when starting to seek, play again
|
||||||
if (!active) {
|
if (!active) {
|
||||||
|
|
Loading…
Reference in a new issue