-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(player): implement keyboard keys
- Loading branch information
Showing
5 changed files
with
75 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
onKeyStroke, | ||
whenever, | ||
useMagicKeys, | ||
useThrottleFn | ||
} from '@vueuse/core'; | ||
import playbackManager from '@/store/playbackManager'; | ||
|
||
import { isTizen, isWebOS } from '@/utils/browser-detection'; | ||
|
||
/** | ||
* Register keyboard player control. | ||
* @param osdHandler - show the player osd for a short period whenever a suitable action is called | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
export function usePlayerKeys(osdHandler = (): void => {}): void { | ||
const keys = useMagicKeys(); | ||
|
||
whenever(keys.mediapause, playbackManager.pause); | ||
whenever(keys.mediaplay, playbackManager.unpause); | ||
whenever(keys.mediaplaypause, playbackManager.playPause); | ||
whenever(keys.mediastop, playbackManager.stop); | ||
whenever(keys.mediatracknext, playbackManager.setNextTrack); | ||
whenever(keys.mediatrackprevious, playbackManager.setPreviousTrack); | ||
whenever(keys.audiovolumemute, playbackManager.toggleMute); | ||
|
||
whenever(keys.space, playbackManager.playPause); | ||
whenever(keys.k, playbackManager.playPause); | ||
whenever(keys.m, playbackManager.toggleMute); | ||
|
||
const throttledForwardFn = useThrottleFn(() => { | ||
playbackManager.skipForward(); | ||
osdHandler(); | ||
}, 100); | ||
|
||
const throttledBackwardFn = useThrottleFn(() => { | ||
playbackManager.skipBackward(); | ||
osdHandler(); | ||
}, 100); | ||
|
||
onKeyStroke('AudioVolumeUp', playbackManager.volumeUp); | ||
onKeyStroke('AudioVolumeDown', playbackManager.volumeDown); | ||
onKeyStroke('j', throttledBackwardFn); | ||
onKeyStroke('l', throttledForwardFn); | ||
|
||
if (!isTizen() && !isWebOS()) { | ||
onKeyStroke('ArrowUp', playbackManager.volumeUp); | ||
onKeyStroke('ArrowDown', playbackManager.volumeDown); | ||
onKeyStroke('ArrowLeft', throttledBackwardFn); | ||
onKeyStroke('ArrowRight', throttledForwardFn); | ||
} | ||
} |
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