From c800000ba4205ad16288656b15b438814175d1b6 Mon Sep 17 00:00:00 2001 From: ElementalAlchemist Date: Sat, 30 Oct 2021 01:37:38 -0500 Subject: [PATCH] Store the user's volume level --- thrimbletrimmer/scripts/common.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/thrimbletrimmer/scripts/common.js b/thrimbletrimmer/scripts/common.js index b5fa764..3abf1c7 100644 --- a/thrimbletrimmer/scripts/common.js +++ b/thrimbletrimmer/scripts/common.js @@ -72,9 +72,23 @@ async function loadVideoPlayer(playlistURL) { }; const player = videojs("video", defaultOptions); - return new Promise((resolve, reject) => { + return new Promise((resolve, _reject) => { player.ready(() => { - player.volume(0.5); // Initialize to half volume + const volume = +(localStorage.getItem("volume") ?? 0.5); + if (isNaN(volume)) { + volume = 0.5; + } else if (volume < 0) { + volume = 0; + } else if (volume > 1) { + volume = 1; + } + player.volume(volume); + + player.on("volumechange", () => { + const player = getVideoJS(); + const volume = player.volume(); + localStorage.setItem("volume", volume); + }); resolve(); }); });