-
-
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.
- Loading branch information
Showing
6 changed files
with
248 additions
and
59 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,55 @@ | ||
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 | ||
*/ | ||
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 callHandler = (): void => { | ||
if (osdHandler) { | ||
osdHandler(); | ||
} | ||
}; | ||
|
||
const throttledForwardFn = useThrottleFn(() => { | ||
playbackManager.skipForward(); | ||
callHandler(); | ||
}, 100); | ||
|
||
const throttledBackwardFn = useThrottleFn(() => { | ||
playbackManager.skipBackward(); | ||
callHandler(); | ||
}, 100); | ||
|
||
onKeyStroke(['j', 'ArrowLeft'], throttledBackwardFn); | ||
onKeyStroke(['l', 'ArrowRight'], throttledForwardFn); | ||
onKeyStroke(['AudioVolumeUp'], playbackManager.volumeUp); | ||
onKeyStroke(['AudioVolumeDown'], playbackManager.volumeDown); | ||
|
||
if (!isTizen() && !isWebOS()) { | ||
onKeyStroke(['ArrowUp'], playbackManager.volumeUp); | ||
onKeyStroke(['ArrowDown'], playbackManager.volumeDown); | ||
} | ||
} |
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
Oops, something went wrong.