From 471602efefd489087598a450dede87d4055db708 Mon Sep 17 00:00:00 2001 From: Punyakrit Date: Thu, 16 May 2024 23:46:21 +0530 Subject: [PATCH] add keyboard control for and video progress handling --- package.json | 2 +- src/components/VideoPlayer2.tsx | 43 ++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4abcf7930..f88c4c3ff 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,6 @@ "prettier": "^3.2.4", "prisma": "^5.6.0", "tailwindcss": "^3.3.0", - "ts-node": "^10.9.2", + "ts-node": "^10.9.2" } } diff --git a/src/components/VideoPlayer2.tsx b/src/components/VideoPlayer2.tsx index b7a484689..526d2dca1 100644 --- a/src/components/VideoPlayer2.tsx +++ b/src/components/VideoPlayer2.tsx @@ -40,6 +40,7 @@ export const VideoPlayer: FunctionComponent = ({ const [player, setPlayer] = useState(null); const searchParams = useSearchParams(); const vidUrl = options.sources[0].src; + useEffect(() => { const t = searchParams.get('timestamp'); if (contentId && player && !t) { @@ -146,7 +147,7 @@ export const VideoPlayer: FunctionComponent = ({ player.currentTime(player.currentTime() - 5); event.stopPropagation(); break; - case 'ArrowUp': // Arrow up for increasing volume + case 'ArrowUp': // Arrow up for increasing volume event.preventDefault(); player.volume(player.volume() + 0.1); event.stopPropagation(); @@ -202,6 +203,46 @@ export const VideoPlayer: FunctionComponent = ({ } } break; + case 'Digit1': + player.currentTime(player.duration() * 0.1); + event.stopPropagation(); + break; + case 'Digit2': + player.currentTime(player.duration() * 0.2); + event.stopPropagation(); + break; + case 'Digit3': + player.currentTime(player.duration() * 0.3); + event.stopPropagation(); + break; + case 'Digit4': + player.currentTime(player.duration() * 0.4); + event.stopPropagation(); + break; + case 'Digit5': + player.currentTime(player.duration() * 0.5); + event.stopPropagation(); + break; + case 'Digit6': + player.currentTime(player.duration() * 0.6); + event.stopPropagation(); + break; + case 'Digit7': + player.currentTime(player.duration() * 0.7); + event.stopPropagation(); + break; + case 'Digit8': + player.currentTime(player.duration() * 0.8); + event.stopPropagation(); + break; + case 'Digit9': + player.currentTime(player.duration() * 0.9); + event.stopPropagation(); + break; + case 'Digit0': + player.currentTime(0); + event.stopPropagation(); + break; } } };