overte-HifiExperiments/unpublishedScripts/DomainContent/CellScience/backgroundMusicAC.js
James B. Pollack a80641a2c4 changes
2016-02-08 13:15:49 -08:00

97 lines
No EOL
2.5 KiB
JavaScript

var soundMap = [{
name: 'Cells',
url: "http://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/Cells.wav",
audioOptions: {
position: {
x: 15850,
y: 15850,
z: 15850
},
volume: 0.4,
loop: true
}
}, {
name: 'Cell Layout',
url: "http://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/CellLayout.wav",
audioOptions: {
position: {
x: 15950,
y: 15950,
z: 15950
},
volume: 0.4,
loop: true
}
}, {
name: 'Ribsome',
url: "http://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/Ribosome.wav",
audioOptions: {
position: {
x: 15650,
y: 15650,
z: 15650
},
volume: 0.4,
loop: true
}
}, {
name: 'Hexokinase',
url: "http://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/Hexokinase.wav",
audioOptions: {
position: {
x: 15750,
y: 15750,
z: 15750
},
volume: 0.4,
loop: true
}
}
];
function loadSounds() {
soundMap.forEach(function(soundData) {
soundData.sound = SoundCache.getSound(soundData.url);
});
}
function playSound(soundData) {
if (soundData.injector) {
// try/catch in case the injector QObject has been deleted already
try {
soundData.injector.stop();
} catch (e) {
print('error playing sound' + e)
}
}
soundData.injector = Audio.playSound(soundData.sound, soundData.audioOptions);
}
function checkDownloaded(soundData) {
if (soundData.sound.downloaded) {
Script.clearInterval(soundData.downloadTimer);
if (soundData.hasOwnProperty('playAtInterval')) {
soundData.playingInterval = Script.setInterval(function() {
playSound(soundData)
}, soundData.playAtInterval);
} else {
playSound(soundData);
}
}
}
function startCheckDownloadedTimers() {
soundMap.forEach(function(soundData) {
soundData.downloadTimer = Script.setInterval(function() {
checkDownloaded(soundData);
}, 1000);
});
}
loadSounds();
startCheckDownloadedTimers();