From 87eccb3f51e3256d149899c398d24c1ed8d820a8 Mon Sep 17 00:00:00 2001 From: Tony Ribeiro Date: Sat, 19 Aug 2023 01:07:10 +0200 Subject: [PATCH] Prototype of dynamic background music using expression extension --- .../scripts/extensions/expressions/index.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/public/scripts/extensions/expressions/index.js b/public/scripts/extensions/expressions/index.js index 52715ea99..5838cbaaf 100644 --- a/public/scripts/extensions/expressions/index.js +++ b/public/scripts/extensions/expressions/index.js @@ -994,6 +994,44 @@ async function setExpression(character, expression, force) { } + + // HACK: music update + console.error(" CODE INJECTION START") + const music_file_path = "/characters/"+character+"/music/"+expression+"_0.mp3" + console.log(" Checking audio file",music_file_path) + fetch(music_file_path) + .then(response => { + if (!response.ok) { + console.log(" File not found!") + } + else { + console.log(" Playing emotion",expression) + const audio = $("#music_background"); + + audio.animate({volume: 0.0}, 2000, function() { + audio.attr("src",music_file_path) + audio[0].play(); + audio.volume = 1.0; + audio.animate({volume: 1.0}, 2000); + }) + + // Set the point in playback that fadeout begins. This is for a 2 second fade out. + var fadeAudio = setInterval(function () { + + // Only fade if past the fade out point or not at zero already + if (audio.volume != 0.0) { + audio.volume -= 0.1; + } + // When volume at zero stop all the intervalling + if (audio.volume === 0.0) { + clearInterval(fadeAudio); + + } + }, 200); + + } + }); + console.error(" CODE INJECTION END") } function onClickExpressionImage() { @@ -1285,6 +1323,8 @@ function setExpressionOverrideHtml(forceClear = false) { + +