From d70662d1022b35c9c5fd08871fc848e954ee8e6a Mon Sep 17 00:00:00 2001 From: Nameless <127152751+NexusKitten@users.noreply.github.com> Date: Thu, 13 Mar 2025 17:48:28 -0400 Subject: [PATCH 1/8] Add files via upload --- extensions/Lily/Video.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index f33c24fb0e..7534b3bcba 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -42,6 +42,8 @@ /** @type {string} */ this.videoSrc = videoSrc; + this.videoVolume = 1; + this.videoError = false; this.readyPromise = new Promise((resolve) => { @@ -146,6 +148,17 @@ } }); + // Updated code to apply the project's volume to that of the video. + // This allows the volume to interact with Scratch Addons and Sound Expanded. + runtime.on("AFTER_EXECUTE", () => { + for (const skin of renderer._allSkins) { + if (skin instanceof VideoSkin) { + let projectVolume = runtime.audioEngine.inputNode.gain.value; + skin.videoElement.volume = skin.videoVolume * projectVolume; + } + } + }); + runtime.on("RUNTIME_PAUSED", () => { for (const skin of renderer._allSkins) { if (skin instanceof VideoSkin) { @@ -598,7 +611,7 @@ case "duration": return videoSkin.videoElement.duration; case "volume": - return videoSkin.videoElement.volume * 100; + return videoSkin.videoVolume * 100; case "width": return videoSkin.size[0]; case "height": @@ -682,7 +695,7 @@ if (!videoSkin) return; const value = Cast.toNumber(args.VALUE); - videoSkin.videoElement.volume = Math.min(1, Math.max(0, value / 100)); + videoSkin.videoVolume = Math.min(1, Math.max(0, value / 100)); } setPlaybackRate(args) { From 17920f207b0e4b7967819a5e66e85e8f2ab5d186 Mon Sep 17 00:00:00 2001 From: Nameless <127152751+NexusKitten@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:49:14 -0400 Subject: [PATCH 2/8] hopefully(?) resolve the issue being discussed --- extensions/Lily/Video.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index 7534b3bcba..1d2bdb7bbc 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -151,13 +151,18 @@ // Updated code to apply the project's volume to that of the video. // This allows the volume to interact with Scratch Addons and Sound Expanded. runtime.on("AFTER_EXECUTE", () => { + this.updateAudio(); + }); + + this.updateAudio = function () { for (const skin of renderer._allSkins) { if (skin instanceof VideoSkin) { let projectVolume = runtime.audioEngine.inputNode.gain.value; skin.videoElement.volume = skin.videoVolume * projectVolume; + console.log(skin.videoElement.volume); } } - }); + } runtime.on("RUNTIME_PAUSED", () => { for (const skin of renderer._allSkins) { @@ -696,6 +701,7 @@ const value = Cast.toNumber(args.VALUE); videoSkin.videoVolume = Math.min(1, Math.max(0, value / 100)); + this.updateAudio(); } setPlaybackRate(args) { From 902a768f72a935c427e0cbfaae2b7b943cb207d2 Mon Sep 17 00:00:00 2001 From: "DangoCat[bot]" Date: Fri, 14 Mar 2025 21:50:23 +0000 Subject: [PATCH 3/8] [Automated] Format code --- extensions/Lily/Video.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index 1d2bdb7bbc..d6c8b9b938 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -162,7 +162,7 @@ console.log(skin.videoElement.volume); } } - } + }; runtime.on("RUNTIME_PAUSED", () => { for (const skin of renderer._allSkins) { From d494055a87d6f5959cc0be729e6e1a8773873280 Mon Sep 17 00:00:00 2001 From: Nameless <127152751+NexusKitten@users.noreply.github.com> Date: Fri, 14 Mar 2025 17:51:04 -0400 Subject: [PATCH 4/8] remove the leftover console.log() --- extensions/Lily/Video.js | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index d6c8b9b938..599e8f0e3a 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -159,7 +159,6 @@ if (skin instanceof VideoSkin) { let projectVolume = runtime.audioEngine.inputNode.gain.value; skin.videoElement.volume = skin.videoVolume * projectVolume; - console.log(skin.videoElement.volume); } } }; From 31768a221a3c9aed5cc99b218994ef5cbab05798 Mon Sep 17 00:00:00 2001 From: Nameless <127152751+NexusKitten@users.noreply.github.com> Date: Fri, 18 Apr 2025 16:51:51 -0400 Subject: [PATCH 5/8] Update Video.js --- extensions/Lily/Video.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index 599e8f0e3a..fdabb080cf 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -148,21 +148,10 @@ } }); - // Updated code to apply the project's volume to that of the video. - // This allows the volume to interact with Scratch Addons and Sound Expanded. runtime.on("AFTER_EXECUTE", () => { this.updateAudio(); }); - this.updateAudio = function () { - for (const skin of renderer._allSkins) { - if (skin instanceof VideoSkin) { - let projectVolume = runtime.audioEngine.inputNode.gain.value; - skin.videoElement.volume = skin.videoVolume * projectVolume; - } - } - }; - runtime.on("RUNTIME_PAUSED", () => { for (const skin of renderer._allSkins) { if (skin instanceof VideoSkin) { @@ -172,6 +161,8 @@ } }); + // Updated code to apply the project's volume to that of the video. + // This allows the volume to interact with Scratch Addons and Sound Expanded. runtime.on("RUNTIME_UNPAUSED", () => { for (const skin of renderer._allSkins) { if (skin instanceof VideoSkin) { @@ -182,6 +173,15 @@ }); } + updateAudio() { + for (const skin of renderer._allSkins) { + if (skin instanceof VideoSkin) { + let projectVolume = runtime.audioEngine.inputNode.gain.value; + skin.videoElement.volume = skin.videoVolume * projectVolume; + } + } + }; + getInfo() { return { id: "lmsVideo", From 6fab42afcd68da81ab5ff0786f84d13cb33ec764 Mon Sep 17 00:00:00 2001 From: "DangoCat[bot]" Date: Fri, 18 Apr 2025 20:52:58 +0000 Subject: [PATCH 6/8] [Automated] Format code --- extensions/Lily/Video.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index fdabb080cf..09020610b4 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -180,7 +180,7 @@ skin.videoElement.volume = skin.videoVolume * projectVolume; } } - }; + } getInfo() { return { From 3b6150077b7d00b004d36616a3048ab6d75d5e0d Mon Sep 17 00:00:00 2001 From: Nameless <127152751+NexusKitten@users.noreply.github.com> Date: Fri, 18 Apr 2025 17:56:35 -0400 Subject: [PATCH 7/8] this should fix the memory leak. hypothetically. maybe. i'm actually not too sure. --- extensions/Lily/Video.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index 09020610b4..f189673554 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -31,6 +31,17 @@ elementContainer.ariaHidden = "true"; document.body.appendChild(elementContainer); + // Updated code to apply the project's volume to that of the video. + // This allows the volume to interact with Scratch Addons and Sound Expanded. + const updateAudio = function() { + for (const skin of renderer._allSkins) { + if (skin instanceof VideoSkin) { + let projectVolume = runtime.audioEngine.inputNode.gain.value; + skin.videoElement.volume = skin.videoVolume * projectVolume; + } + } + }; + const BitmapSkin = runtime.renderer.exports.BitmapSkin; class VideoSkin extends BitmapSkin { constructor(id, renderer, videoName, videoSrc) { @@ -126,6 +137,7 @@ } dispose() { + runtime.off("AFTER_EXECUTE", updateAudio); super.dispose(); this.videoElement.pause(); this.videoElement.remove(); @@ -148,9 +160,7 @@ } }); - runtime.on("AFTER_EXECUTE", () => { - this.updateAudio(); - }); + runtime.on("AFTER_EXECUTE", updateAudio); runtime.on("RUNTIME_PAUSED", () => { for (const skin of renderer._allSkins) { @@ -161,8 +171,6 @@ } }); - // Updated code to apply the project's volume to that of the video. - // This allows the volume to interact with Scratch Addons and Sound Expanded. runtime.on("RUNTIME_UNPAUSED", () => { for (const skin of renderer._allSkins) { if (skin instanceof VideoSkin) { @@ -173,15 +181,6 @@ }); } - updateAudio() { - for (const skin of renderer._allSkins) { - if (skin instanceof VideoSkin) { - let projectVolume = runtime.audioEngine.inputNode.gain.value; - skin.videoElement.volume = skin.videoVolume * projectVolume; - } - } - } - getInfo() { return { id: "lmsVideo", @@ -700,7 +699,7 @@ const value = Cast.toNumber(args.VALUE); videoSkin.videoVolume = Math.min(1, Math.max(0, value / 100)); - this.updateAudio(); + updateAudio(); } setPlaybackRate(args) { From 95eb998574e0357bff2d89c132207dffba503fad Mon Sep 17 00:00:00 2001 From: "DangoCat[bot]" Date: Fri, 18 Apr 2025 21:57:44 +0000 Subject: [PATCH 8/8] [Automated] Format code --- extensions/Lily/Video.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/Lily/Video.js b/extensions/Lily/Video.js index f189673554..4f2c7565bd 100644 --- a/extensions/Lily/Video.js +++ b/extensions/Lily/Video.js @@ -33,7 +33,7 @@ // Updated code to apply the project's volume to that of the video. // This allows the volume to interact with Scratch Addons and Sound Expanded. - const updateAudio = function() { + const updateAudio = function () { for (const skin of renderer._allSkins) { if (skin instanceof VideoSkin) { let projectVolume = runtime.audioEngine.inputNode.gain.value;