-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix hotkeys issues * hotkeys improvements * Update src/shared/components/VideoPlayer/VideoPlayer.tsx Co-authored-by: Rafał Pawłow <[email protected]> * Update src/shared/components/VideoPlayer/VideoPlayer.tsx * Update src/shared/components/VideoPlayer/VideoPlayer.tsx * Update src/shared/components/VideoPlayer/VideoPlayer.tsx * rebase Co-authored-by: Rafał Pawłow <[email protected]>
- Loading branch information
1 parent
1788cc7
commit 306cabb
Showing
5 changed files
with
118 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { VideoJsPlayer } from 'video.js' | ||
|
||
export const VOLUME_STEP = 0.1 | ||
|
||
export enum CustomVideojsEvents { | ||
BackwardFiveSec = 'BACKWARD_FIVE_SEC', | ||
BackwardTenSec = 'BACKWARD_TEN_SEC', | ||
ForwardFiveSec = 'FORWARD_FIVE_SEC', | ||
ForwardTenSec = 'FORWARD_TEN_SEC', | ||
Muted = 'MUTED', | ||
Unmuted = 'UNMUTED', | ||
VolumeIncrease = 'VOLUME_INCREASE', | ||
VolumeDecrease = 'VOLUME_DECREASE', | ||
PlayControl = 'PLAY_CONTROL', | ||
PauseControl = 'PAUSE_CONTROL', | ||
} | ||
|
||
export const hotkeysHandler = (event: KeyboardEvent, playerInstance: VideoJsPlayer) => { | ||
if (!playerInstance) { | ||
return | ||
} | ||
const currentTime = playerInstance.currentTime() | ||
const currentVolume = Number(playerInstance.volume().toFixed(2)) | ||
const isMuted = playerInstance.muted() | ||
const isFullscreen = playerInstance.isFullscreen() | ||
const isPaused = playerInstance.paused() | ||
|
||
switch (event.code) { | ||
case 'Space': | ||
case 'KeyK': | ||
if (isPaused) { | ||
playerInstance.play() | ||
playerInstance.trigger(CustomVideojsEvents.PlayControl) | ||
} else { | ||
playerInstance.pause() | ||
playerInstance.trigger(CustomVideojsEvents.PauseControl) | ||
} | ||
return | ||
case 'ArrowLeft': | ||
playerInstance.currentTime(currentTime - 5) | ||
playerInstance.trigger(CustomVideojsEvents.BackwardFiveSec) | ||
return | ||
case 'ArrowRight': | ||
playerInstance.currentTime(currentTime + 5) | ||
playerInstance.trigger(CustomVideojsEvents.ForwardFiveSec) | ||
return | ||
case 'KeyJ': | ||
playerInstance.currentTime(currentTime - 10) | ||
playerInstance.trigger(CustomVideojsEvents.BackwardTenSec) | ||
return | ||
case 'KeyL': | ||
playerInstance.currentTime(currentTime + 10) | ||
playerInstance.trigger(CustomVideojsEvents.ForwardTenSec) | ||
return | ||
case 'ArrowUp': | ||
if (playerInstance.muted()) { | ||
playerInstance.muted(false) | ||
} | ||
if (currentVolume <= 1) { | ||
playerInstance.volume(Math.min(currentVolume + VOLUME_STEP, 1)) | ||
} | ||
playerInstance.trigger(CustomVideojsEvents.VolumeIncrease) | ||
return | ||
case 'ArrowDown': | ||
if (currentVolume >= 0) { | ||
playerInstance.volume(Math.max(currentVolume - VOLUME_STEP, 0)) | ||
} | ||
playerInstance.trigger(CustomVideojsEvents.VolumeDecrease) | ||
return | ||
case 'KeyM': | ||
if (isMuted) { | ||
playerInstance.trigger(CustomVideojsEvents.Unmuted) | ||
playerInstance.muted(false) | ||
} else { | ||
playerInstance.trigger(CustomVideojsEvents.Muted) | ||
playerInstance.muted(true) | ||
} | ||
return | ||
case 'KeyF': | ||
if (isFullscreen) { | ||
playerInstance.exitFullscreen() | ||
} else { | ||
playerInstance.requestFullscreen() | ||
} | ||
return | ||
default: | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters