From 40f6a72ad7c92e690d2714fc1c669191fcf79e89 Mon Sep 17 00:00:00 2001 From: Mike Lang Date: Fri, 8 Nov 2019 23:46:03 -0800 Subject: [PATCH] thrimbletrimmer: Add keyboard shortcuts -/= to adjust playback speed --- thrimbletrimmer/scripts/keyboardShortcuts.js | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/thrimbletrimmer/scripts/keyboardShortcuts.js b/thrimbletrimmer/scripts/keyboardShortcuts.js index 627df05..71191e8 100644 --- a/thrimbletrimmer/scripts/keyboardShortcuts.js +++ b/thrimbletrimmer/scripts/keyboardShortcuts.js @@ -1,3 +1,18 @@ +function changeSpeed(direction) { + var speeds = [0.5, 1, 1.25, 1.5, 2]; + var currentIndex = speeds.indexOf(player.playbackRate()); + if (currentIndex < 0) { + // not present + return; + } + var newIndex = currentIndex + direction; + if (newIndex < 0 || newIndex >= speeds.length) { + // out of range + return + } + player.playbackRate(speeds[newIndex]); +} + document.addEventListener('keypress', (event) => { //if(event.target.nodeName == "BODY") { if(event.target.nodeName !== "INPUT" && event.target.nodeName !== "TEXTAREA") { @@ -24,6 +39,12 @@ document.addEventListener('keypress', (event) => { case "o": player.trimmingControls().updateTrimTimes(player.trimmingControls().options.startTrim, player.currentTime()); break; + case "=": + changeSpeed(1); + break + case "-": + changeSpeed(-1); + break case "0": player.currentTime(0); break;