// Happy Boom Box // boomBoxEntityScript.js // Licensed under the Apache 2.0 License // Music provided by Bensound (function(){ var LOAD_WAIT = 500; var selfEntityID; var audioInjector; function BoomBox(){ } BoomBox.prototype = { remotelyCallable: ['playMusic', 'stopMusic'], preload: function(entityID) { selfEntityID = entityID; }, unload: function () { if (audioInjector && audioInjector.playing) { audioInjector.stop(); } }, playMusic: function(entityID, args) { var sound = SoundCache.getSound(args[0]); var audioInjectorOptions = { volume: 0.5, loop: false, position: Entities.getEntityProperties(selfEntityID, 'position').position }; print ("Audio Options: " + JSON.stringify(audioInjectorOptions)); if (audioInjector && audioInjector.playing) { audioInjector.stop(); } Script.setTimeout(function(){ audioInjector = Audio.playSound(sound, audioInjectorOptions); }, LOAD_WAIT); }, stopMusic : function() { if (audioInjector && audioInjector.playing) { audioInjector.stop(); } } }; return new BoomBox(); });