From 0b06cf1dfbf990b1e6c786906b6f9189e9a1e21b Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Wed, 21 Oct 2015 10:53:32 -0700 Subject: [PATCH] cleanup --- examples/toys/AC_scripts/toybox_sounds.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/toys/AC_scripts/toybox_sounds.js b/examples/toys/AC_scripts/toybox_sounds.js index 87d2bcc75a..67985a5938 100644 --- a/examples/toys/AC_scripts/toybox_sounds.js +++ b/examples/toys/AC_scripts/toybox_sounds.js @@ -8,7 +8,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - var soundMap = [{ name: 'river water', url: "http://hifi-public.s3.amazonaws.com/ryan/Water_Lap_River_Edge_Gentle.L.wav", @@ -90,7 +89,6 @@ function loadSounds() { }); } - function playSound(soundData) { if (soundData.injector) { // try/catch in case the injector QObject has been deleted already @@ -103,10 +101,12 @@ function playSound(soundData) { function checkDownloaded(soundData) { if (soundData.sound.downloaded) { + Script.clearInterval(soundData.downloadTimer); + if (soundData.hasOwnProperty('playAtInterval')) { soundData.playingInterval = Script.setInterval(function() { - playSound(soundData); + playSound(soundData) }, soundData.playAtInterval); } else { playSound(soundData); @@ -118,23 +118,26 @@ function checkDownloaded(soundData) { function startCheckDownloadedTimers() { soundMap.forEach(function(soundData) { soundData.downloadTimer = Script.setInterval(function() { - checkDownloaded(soundData) + checkDownloaded(soundData); }, 1000); }); } Script.scriptEnding.connect(function() { soundMap.forEach(function(soundData) { + if (soundData.hasOwnProperty("injector")) { soundData.injector.stop(); } + if (soundData.hasOwnProperty("downloadTimer")) { Script.clearInterval(soundData.downloadTimer); - } + if (soundData.hasOwnProperty("playingInterval")) { Script.clearInterval(soundData.playingInterval); } + }); });