mirror of
https://github.com/sussy-code/smov.git
synced 2024-12-20 14:37:43 +01:00
more chromecast fixes
Co-authored-by: Jip Frijlink <JipFr@users.noreply.github.com> Co-authored-by: James Hawkins <jhawki2005@gmail.com> Co-authored-by: William Oldham <wegg7250@gmail.com>
This commit is contained in:
parent
b886443ea7
commit
398644951e
3 changed files with 18 additions and 2 deletions
|
@ -4,6 +4,7 @@ import { useVideoPlayerDescriptor } from "@/video/state/hooks";
|
|||
import { useMediaPlaying } from "@/video/state/logic/mediaplaying";
|
||||
import { useProgress } from "@/video/state/logic/progress";
|
||||
import { useControls } from "@/video/state/logic/controls";
|
||||
import { useMisc } from "@/video/state/logic/misc";
|
||||
|
||||
interface Props {
|
||||
startAt?: number;
|
||||
|
@ -15,6 +16,7 @@ export function ProgressListenerController(props: Props) {
|
|||
const mediaPlaying = useMediaPlaying(descriptor);
|
||||
const progress = useProgress(descriptor);
|
||||
const controls = useControls(descriptor);
|
||||
const misc = useMisc(descriptor);
|
||||
const didInitialize = useRef<true | null>(null);
|
||||
const lastTime = useRef<number>(props.startAt ?? 0);
|
||||
|
||||
|
@ -46,6 +48,17 @@ export function ProgressListenerController(props: Props) {
|
|||
didInitialize.current = true;
|
||||
}, [didInitialize, props, progress, mediaPlaying, controls]);
|
||||
|
||||
// when switching state providers
|
||||
// TODO stateProviderId is somehow ALWAYS "video"
|
||||
const lastStateProviderId = useRef<string | null>(null);
|
||||
const stateProviderId = useMemo(() => misc.stateProviderId, [misc]);
|
||||
useEffect(() => {
|
||||
if (lastStateProviderId.current === stateProviderId) return;
|
||||
if (mediaPlaying.isFirstLoading) return;
|
||||
lastStateProviderId.current = stateProviderId;
|
||||
controls.setTime(lastTime.current);
|
||||
}, [controls, mediaPlaying, stateProviderId]);
|
||||
|
||||
useEffect(() => {
|
||||
// if it initialized, but media starts loading for the first time again.
|
||||
// reset initalized so it will restore time again
|
||||
|
|
|
@ -176,7 +176,10 @@ export function createCastingStateProvider(
|
|||
state.mediaPlaying.isLoading = e.value === "BUFFERING";
|
||||
state.mediaPlaying.isPaused = e.value !== "PLAYING";
|
||||
state.mediaPlaying.isPlaying = e.value === "PLAYING";
|
||||
if (e.value === "PLAYING") state.mediaPlaying.hasPlayedOnce = true;
|
||||
if (e.value === "PLAYING") {
|
||||
state.mediaPlaying.hasPlayedOnce = true;
|
||||
state.mediaPlaying.isFirstLoading = false;
|
||||
}
|
||||
updateMediaPlaying(descriptor, state);
|
||||
break;
|
||||
case "isMuted":
|
||||
|
|
|
@ -26,11 +26,11 @@ export function unsetStateProvider(
|
|||
!state.stateProvider ||
|
||||
state.stateProvider?.getId() !== stateProviderId
|
||||
) {
|
||||
state.stateProviderId = "video"; // go back to video when casting stops
|
||||
return;
|
||||
}
|
||||
state.stateProvider = null;
|
||||
state.stateProviderId = "video"; // go back to video when casting stops
|
||||
updateMisc(descriptor, state);
|
||||
}
|
||||
|
||||
export function handleBuffered(time: number, buffered: TimeRanges): number {
|
||||
|
|
Loading…
Reference in a new issue