diff options
author | Minteck <nekostarfan@gmail.com> | 2021-06-10 22:00:49 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-06-10 22:00:49 +0200 |
commit | dfbe8476aa6323bf1d9e699b5e08165a8403b21c (patch) | |
tree | e2fab6a5986c1f7b9d55a7b1009263ff98b5a33c /views/script/core_music.js | |
parent | 3e62534eb7db3011ef540b6053811d48761dda21 (diff) | |
download | kartik-client-dfbe8476aa6323bf1d9e699b5e08165a8403b21c.tar.gz kartik-client-dfbe8476aa6323bf1d9e699b5e08165a8403b21c.tar.bz2 kartik-client-dfbe8476aa6323bf1d9e699b5e08165a8403b21c.zip |
(Pre)final commit !
Diffstat (limited to 'views/script/core_music.js')
-rw-r--r-- | views/script/core_music.js | 89 |
1 files changed, 44 insertions, 45 deletions
diff --git a/views/script/core_music.js b/views/script/core_music.js index adb0ae2..4b85ebb 100644 --- a/views/script/core_music.js +++ b/views/script/core_music.js @@ -1,11 +1,34 @@ -global.csng = null; +/*global.csng = null; global.csp1 = null; global.csp2 = null; -global.cspn = 1; +global.cspn = 1;*/ +global.musicElement = new Audio(); const musicIpc = require('electron').ipcRenderer; musicIpc.on('setmusic', (event, args) => { - try { csp1.volume = 0; } catch (e) {} + if (!musicElement.paused) { + csi1 = setInterval(() => { + if (musicElement.volume <= 0.05) { + clearInterval(csi1); + musicElement.src = args; + musicElement.play(); + musicElement.volume = 0; + csi2 = setInterval(() => { + if (musicElement.volume >= 0.95) { + clearInterval(csi2); + return; + } + musicElement.volume = musicElement.volume + 0.05; + }, 100) + return; + } + musicElement.volume = musicElement.volume - 0.05; + }, 100) + } else { + musicElement.src = args; + musicElement.play(); + } + /*try { csp1.volume = 0; } catch (e) {} try { csp2.volume = 0; } catch (e) {} song = args; @@ -61,53 +84,29 @@ musicIpc.on('setmusic', (event, args) => { csng = song; cspn = 1; } - } + }*/ }) musicIpc.on('fademusic', (event) => { - if (cspn === 1) { - if (csp1 !== null) { - csi1 = setInterval(() => { - if (csp1.volume <= 0.05) { - clearInterval(csi1); - return; - } - csp1.volume = csp1.volume - 0.05; - }, 100) - } - } else { - if (csp2 !== null) { - csi2 = setInterval(() => { - if (csp2.volume <= 0.05) { - clearInterval(csi2); - return; - } - csp2.volume = csp2.volume - 0.05; - }, 100) - } + if (!musicElement.paused) { + csi1 = setInterval(() => { + if (musicElement.volume <= 0.3) { + clearInterval(csi1); + return; + } + musicElement.volume = musicElement.volume - 0.05; + }, 100) } }) musicIpc.on('unfademusic', (event) => { - if (cspn === 1) { - if (csp1 !== null) { - csi1 = setInterval(() => { - if (csp1.volume >= 0.95) { - clearInterval(csi1); - return; - } - csp1.volume = csp1.volume + 0.05; - }, 100) - } - } else { - if (csp2 !== null) { - csi2 = setInterval(() => { - if (csp2.volume >= 0.95) { - clearInterval(csi2); - return; - } - csp2.volume = csp2.volume + 0.05; - }, 100) - } + if (!musicElement.paused) { + csi1 = setInterval(() => { + if (musicElement.volume >= 0.95) { + clearInterval(csi1); + return; + } + musicElement.volume = musicElement.volume + 0.05; + }, 100) } -})
\ No newline at end of file +}) |