(function(){ //var SOUND_URL = "http://hifi-content.s3.amazonaws.com/caitlyn/production/pizzaTurntable/newBuiltMixl.wav"; var loopTime = -1; // Loop for how long? -1 is always on. var soundURL = null;//SoundCache.getSound(SOUND_URL); var soundLoop = null; var soundLocal = null; var soundVolume = null; var injector = null; var entityID = null; var properties = null; this.preload = function(pEntityID) { entityID = pEntityID; var intervalID = Script.setInterval(function() { properties = Entities.getEntityProperties(entityID, ["position", "userData"]); if (!properties.userData) { print("Sound emitter "+entityID+" missing user data."); return; } try { var soundData = JSON.parse(properties.userData); // need to check that all this stuff even exists and throw error if not.s soundURL = SoundCache.getSound(soundData.soundURL); soundVolume = soundData.soundVolume; soundLoop = soundData.isLoop; soundLocal = soundData.isLocal; print("GET THE URL "+soundData.soundURL); } catch (e){} if (!injector) { if (soundURL.downloaded) { //Script.clearInterval(intervalID); injector = Audio.playSound(soundURL, { position: properties.position, volume: soundVolume, loop: soundLoop, localOnly: soundLocal }); } } else { injector.setOptions({ position: properties.position }); } }, 1000); }; this.unload = function(){ if (injector) { injector.stop(); injector = null; } }; });