Skip to content

Commit

Permalink
Merge pull request #330 from BloomBooks/videoControls2
Browse files Browse the repository at this point in the history
fix: Pause for touch on video (BL-13957) (#330)
  • Loading branch information
andrew-polk authored Oct 14, 2024
2 parents 8ebaf6a + bad62f4 commit 9ada481
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class Video {
}
this.getVideoElements().forEach(videoElement => {
videoElement.removeAttribute("controls");
videoElement.addEventListener("click", this.handleVideoClick);
const playButton = this.wrapVideoIcon(
videoElement,
// Alternatively, we could import the Material UI icon, make this file a TSX, and use
Expand All @@ -68,7 +69,6 @@ export class Video {
"videoPlayIcon"
);
playButton.addEventListener("click", this.handlePlayClick);
videoElement.addEventListener("click", this.handlePlayClick);
const pauseButton = this.wrapVideoIcon(
videoElement,
getPauseIcon("#ffffff"),
Expand Down Expand Up @@ -156,6 +156,15 @@ export class Video {
}
};

private handleVideoClick = (ev: MouseEvent) => {
const video = ev.currentTarget as HTMLVideoElement;
if (video.paused) {
this.handlePlayClick(ev);
} else {
this.handlePauseClick(ev);
}
};

private handleReplayClick = (ev: MouseEvent) => {
ev.stopPropagation(); // we don't want the navigation bar to toggle on and off
ev.preventDefault();
Expand Down

0 comments on commit 9ada481

Please sign in to comment.