diff --git a/src/components/VideoPlayer2.tsx b/src/components/VideoPlayer2.tsx index da2f26f8e..85f56088e 100644 --- a/src/components/VideoPlayer2.tsx +++ b/src/components/VideoPlayer2.tsx @@ -130,74 +130,74 @@ export const VideoPlayer: FunctionComponent = ({ return; // Do nothing if the active element is an input or textarea } if (!isSidebarOpen) { - switch (event.code) { - case 'Space': // Space bar for play/pause - if (player.paused()) { - player.play(); + switch (event.code) { + case 'Space': // Space bar for play/pause + if (player.paused()) { + player.play(); + event.stopPropagation(); + } else { + player.pause(); + event.stopPropagation(); + } + event.preventDefault(); + break; + case 'ArrowRight': // Right arrow for seeking forward 5 seconds + player.currentTime(player.currentTime() + 5); event.stopPropagation(); - } else { - player.pause(); + break; + case 'ArrowLeft': // Left arrow for seeking backward 5 seconds + player.currentTime(player.currentTime() - 5); event.stopPropagation(); - } - event.preventDefault(); - break; - case 'ArrowRight': // Right arrow for seeking forward 5 seconds - player.currentTime(player.currentTime() + 5); - event.stopPropagation(); - break; - case 'ArrowLeft': // Left arrow for seeking backward 5 seconds - player.currentTime(player.currentTime() - 5); - event.stopPropagation(); - break; - case 'KeyF': // F key for fullscreen - if (player.isFullscreen_) document.exitFullscreen(); - else player.requestFullscreen(); - event.stopPropagation(); - break; - case 'KeyR': // 'R' key to restart playback from the beginning - player.currentTime(0); - event.stopPropagation(); - break; - case 'KeyM': // 'M' key to toggle mute/unmute - if (player.volume() === 0) { - player.volume(1); - } else { - player.volume(0); - } - event.stopPropagation(); - break; - case 'KeyK': // 'K' key for play/pause toggle - if (player.paused()) { - player.play(); - } else { - player.pause(); - } - event.stopPropagation(); - break; - case 'KeyJ': // 'J' key for seeking backward 10 seconds multiplied by the playback rate - player.currentTime( - player.currentTime() - 10 * player.playbackRate(), - ); - event.stopPropagation(); - break; - case 'KeyL': // 'L' key for seeking forward 10 seconds multiplied by the playback rate - player.currentTime( - player.currentTime() + 10 * player.playbackRate(), - ); - event.stopPropagation(); - break; - case 'KeyC': - if (subtitles && player.textTracks().length) { - if (player.textTracks()[0].mode === 'showing') { - player.textTracks()[0].mode = 'hidden'; + break; + case 'KeyF': // F key for fullscreen + if (player.isFullscreen_) document.exitFullscreen(); + else player.requestFullscreen(); + event.stopPropagation(); + break; + case 'KeyR': // 'R' key to restart playback from the beginning + player.currentTime(0); + event.stopPropagation(); + break; + case 'KeyM': // 'M' key to toggle mute/unmute + if (player.volume() === 0) { + player.volume(1); } else { - player.textTracks()[0].mode = 'showing'; + player.volume(0); } - } - break; + event.stopPropagation(); + break; + case 'KeyK': // 'K' key for play/pause toggle + if (player.paused()) { + player.play(); + } else { + player.pause(); + } + event.stopPropagation(); + break; + case 'KeyJ': // 'J' key for seeking backward 10 seconds multiplied by the playback rate + player.currentTime( + player.currentTime() - 10 * player.playbackRate(), + ); + event.stopPropagation(); + break; + case 'KeyL': // 'L' key for seeking forward 10 seconds multiplied by the playback rate + player.currentTime( + player.currentTime() + 10 * player.playbackRate(), + ); + event.stopPropagation(); + break; + case 'KeyC': + if (subtitles && player.textTracks().length) { + if (player.textTracks()[0].mode === 'showing') { + player.textTracks()[0].mode = 'hidden'; + } else { + player.textTracks()[0].mode = 'showing'; + } + } + break; + } } } - } }; const handleKeyUp = (event: any) => {