From 9a3972c43ffca3c5c309b33926bab36c6dec7627 Mon Sep 17 00:00:00 2001 From: Howard Stearns Date: Fri, 12 Feb 2016 17:42:44 -0800 Subject: [PATCH] wait for sound to download --- examples/utilities/diagnostics/orbitingSound.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/utilities/diagnostics/orbitingSound.js b/examples/utilities/diagnostics/orbitingSound.js index baebc17461..11ec9c8358 100644 --- a/examples/utilities/diagnostics/orbitingSound.js +++ b/examples/utilities/diagnostics/orbitingSound.js @@ -28,9 +28,15 @@ var properties = { var objectId = Entities.addEntity(properties); var soundOptions = { position: orbitCenter, loop: true, volume: 0.5 }; -var sound = Audio.playSound(soundClip, soundOptions); +var sound; -function update(deltaTime) { +function update(deltaTime) { + if (!soundClip.downloaded) { + return; + } + if (!sound) { + sound = Audio.playSound(soundClip, soundOptions); // Not until downloaded + } time += deltaTime; currentPosition = { x: orbitCenter.x + Math.cos(time * SPEED) * RADIUS, y: orbitCenter.y, z: orbitCenter.z + Math.sin(time * SPEED) * RADIUS }; trailingLoudness = 0.9 * trailingLoudness + 0.1 * sound.loudness;