Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat hotkey for playback rate #969

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion enjoy/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -716,5 +716,7 @@
"displayContent": "Display content",
"hideContent": "Hide content",
"audioInput": "Audio input",
"textInput": "Text input"
"textInput": "Text input",
"increasePlaybackRate": "Increase playback rate",
"descreasePlaybackRate": "Descrease playback rate"
}
4 changes: 3 additions & 1 deletion enjoy/src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -716,5 +716,7 @@
"displayContent": "显示内容",
"hideContent": "隐藏内容",
"audioInput": "语音输入",
"textInput": "文字输入"
"textInput": "文字输入",
"increasePlaybackRate": "加快播放速度",
"decreasePlaybackRate": "减慢播放速度"
}
33 changes: 32 additions & 1 deletion enjoy/src/renderer/components/medias/media-player-controls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,32 @@ export const MediaPlayerControls = () => {
preventDefault: true,
}
);
useHotkeys(
currentHotkeys.IncreasePlaybackRate,
() => {
setPlaybackRate(
PLAYBACK_RATE_OPTIONS[
PLAYBACK_RATE_OPTIONS.indexOf(playbackRate) + 1
] ?? playbackRate
);
},
{
preventDefault: true,
}
);
useHotkeys(
currentHotkeys.DecreasePlaybackRate,
() => {
setPlaybackRate(
PLAYBACK_RATE_OPTIONS[
PLAYBACK_RATE_OPTIONS.indexOf(playbackRate) - 1
] ?? playbackRate
);
},
{
preventDefault: true,
}
);

/*
* Fit zoom ratio when activeRegion is word or segment
Expand Down Expand Up @@ -514,7 +540,12 @@ export const MediaPlayerControls = () => {
</Button>
</PopoverTrigger>
<PopoverContent className="w-96">
<div className="mb-4 text-center">{t("playbackRate")}</div>
<div
id="media-playback-rate-controller"
className="mb-4 text-center"
>
{t("playbackRate")}
</div>
<div className="w-full rounded-full flex items-center justify-between bg-muted">
{PLAYBACK_RATE_OPTIONS.map((rate, i) => (
<div
Expand Down
38 changes: 38 additions & 0 deletions enjoy/src/renderer/components/preferences/hotkeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,44 @@ export const Hotkeys = () => {

<Separator />

<div className="flex items-center justify-between py-4">
<div className="flex items-center space-x-2 capitalize">
{t("increasePlaybackRate")}
</div>
<kbd
onClick={() =>
handleItemSelected({
name: t("increasePlaybackRate"),
keyName: "IncreasePlaybackRate",
})
}
className="bg-muted px-2 py-1 rounded-md text-sm text-muted-foreground cursor-pointer"
>
{currentHotkeys.IncreasePlaybackRate}
</kbd>
</div>

<Separator />

<div className="flex items-center justify-between py-4">
<div className="flex items-center space-x-2 capitalize">
{t("decreasePlaybackRate")}
</div>
<kbd
onClick={() =>
handleItemSelected({
name: t("decreasePlaybackRate"),
keyName: "DecreasePlaybackRate",
})
}
className="bg-muted px-2 py-1 rounded-md text-sm text-muted-foreground cursor-pointer"
>
{currentHotkeys.DecreasePlaybackRate}
</kbd>
</div>

<Separator />

<div className="flex items-center justify-between py-4">
<div className="flex items-center space-x-2 capitalize">
{t("compare")}
Expand Down
2 changes: 2 additions & 0 deletions enjoy/src/renderer/context/hotkeys-settings-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const defaultKeyMap = {
PlayNextSegment: "N",
Compare: "C",
PronunciationAssessment: "A",
IncreasePlaybackRate: "]",
DecreasePlaybackRate: "[",
// dev tools
OpenDevTools: `${ControlOrCommand}+Shift+I`,
};
Expand Down
Loading