-
-
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): add media control keys
- Loading branch information
Showing
4 changed files
with
53 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,44 @@ | ||
import { | ||
onKeyStroke, | ||
whenever, | ||
useMagicKeys, | ||
useThrottleFn | ||
} from '@vueuse/core'; | ||
import playbackManager from '@/store/playbackManager'; | ||
|
||
/** | ||
* 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.playPause); | ||
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(); | ||
}, 500); | ||
|
||
const throttledBackwardFn = useThrottleFn(() => { | ||
playbackManager.skipBackward(); | ||
callHandler(); | ||
}, 500); | ||
|
||
onKeyStroke(['j', 'ArrowLeft'], throttledBackwardFn); | ||
onKeyStroke(['l', '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