Skip to content

Commit

Permalink
autopause fix
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronshiel committed Oct 8, 2024
1 parent d905d94 commit 3b19c0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 9 additions & 9 deletions client/src/components/video-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element {
getUtterance(state.mentorsById[state.curMentor], UtteranceName.INTRO)
);
const [introEnded, setIntroEnded] = useState<boolean>(false);
const [paused, setPaused] = useState<boolean>(true);
const [firstPauseCleared, setFirstPauseCleared] = useState<boolean>(false);
const { enabled: controlsEnabled, interacted } =
controlsDisableHelper(paused);
controlsDisableHelper(firstPauseCleared);

useEffect(() => {
if (isIntro && videoUrl) {
Expand Down Expand Up @@ -364,12 +364,15 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element {
data-cy={"answer-video-player-wrapper"}
style={{ width: "100%", height: "auto", justifyContent: "center" }}
onMouseOver={() => {
console.log("mouse over");
interacted();
}}
onClick={() => {
console.log("clicked");
interacted();
}}
onMouseMove={() => {
console.log("mouse move");
interacted();
}}
>
Expand All @@ -379,20 +382,16 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element {
style={answerReactPlayerStyling}
className="player-wrapper react-player-wrapper"
data-cy="react-player-answer-video"
controls={controlsEnabled || paused}
controls={controlsEnabled || !firstPauseCleared}
url={state.urlToPlay}
pip={false}
onPause={() => {
interacted();
setPaused(true);
}}
muted={false}
onEnded={endVideo}
ref={reactPlayerRef}
onPlay={() => {
onPlay();
if (paused) {
setPaused(false);
if (!firstPauseCleared) {
setFirstPauseCleared(true);
}
}}
onProgress={({ playedSeconds }) => {
Expand Down Expand Up @@ -454,6 +453,7 @@ export default function VideoPlayer(args: VideoPlayerParams): JSX.Element {
}
}}
onSeek={() => {
console.log("seeked");
interacted();
}}
loop={false}
Expand Down
7 changes: 5 additions & 2 deletions client/src/hooks/controls-disable-helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export interface ControlsDisableHelper {
interacted: () => void;
}

export function controlsDisableHelper(paused: boolean): ControlsDisableHelper {
export function controlsDisableHelper(
firstPauseCleared: boolean
): ControlsDisableHelper {
const [enabled, setEnabled] = useState(true);
const [lastInteractionTime, setLastInteractionTime] = useState(Date.now());

Expand All @@ -23,10 +25,11 @@ export function controlsDisableHelper(paused: boolean): ControlsDisableHelper {
setEnabled(false);
}
},
enabled && !paused ? 1000 : null
enabled && firstPauseCleared ? 1000 : null
);

function interacted() {
console.log("interacted");
setLastInteractionTime(Date.now());
if (!enabled) {
setEnabled(true);
Expand Down

0 comments on commit 3b19c0e

Please sign in to comment.