From 9680f03a90ee92682f549c7730fe5b498a52060a Mon Sep 17 00:00:00 2001 From: aidenlx <31102694+aidenlx@users.noreply.github.com> Date: Tue, 9 Apr 2024 14:24:07 +0800 Subject: [PATCH] feat(command): dedicated command for play and pause --- apps/app/src/media-note/command/media.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/app/src/media-note/command/media.ts b/apps/app/src/media-note/command/media.ts index fde93f0..957eae4 100644 --- a/apps/app/src/media-note/command/media.ts +++ b/apps/app/src/media-note/command/media.ts @@ -14,6 +14,22 @@ const createMediaCommands = (plugin: MxPlugin): Controls[] => [ media.paused = !media.paused; }, }, + { + id: "play", + label: "Play", + icon: "play", + action: (media) => { + media.play(); + }, + }, + { + id: "pause", + label: "Pause", + icon: "pause", + action: (media) => { + media.pause(); + }, + }, ...[0.5, 1, 2, 5, 10, 30, 60].flatMap((sec): Controls[] => [ { id: `forward-${sec}s`, @@ -83,17 +99,17 @@ function speed(plugin: MxPlugin): Controls[] { ...speedOptions .filter((s) => s > 1) .map((speed): Controls => { - let repeated = false; + let repeating = false; const { callback } = handleRepeatHotkey<[MediaPlayerInstance]>(plugin, { onKeyDown(evt, media) { - if (evt.repeat) { - repeated = true; + if (evt.repeat && !repeating) { + repeating = true; media.playbackRate = speed; notifyManualHide(`Fast forwarding at ${speed}x`); } }, onKeyUp(_evt, media) { - if (repeated) { + if (repeating) { media.playbackRate = 1; notice?.hide(); }