overte/examples/audioExamples/acAudioSearching/ACAudioSearchAndInject.js
2016-02-02 14:50:30 -08:00

53 lines
No EOL
1.5 KiB
JavaScript

//
// ACAudioSearchAndInject.js
// audio
//
// Created by Eric Levin 2/1/2016
// Copyright 2016 High Fidelity, Inc.
// This AC script constantly searches for entities with a special userData field that specifies audio settings, and then
// injects the sound with the specified URL with other specified settings (playback volume) or playback at interval, or random interval
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
Script.include("https://rawgit.com/highfidelity/hifi/master/examples/libraries/utils.js");
var ENTITY_QUERY_INTERVAL = 2000;
var SOUND_DATA_KEY = "soundKey";
var MESSAGE_CHANNEL = "Hifi-Sound-Entity";
// Map of all sound entities in domain- key is entity id, value is data
var soundEntities = {};
EntityViewer.setPosition({
x: 0,
y: 0,
z: 0
});
EntityViewer.setKeyholeRadius(60000);
Entities.setPacketsPerSecond(6000);
var DEFAULT_SOUND_DATA = {
volume: 0.5,
loop: false
};
print("EBL STARTING AC SCRIPT");
function messageReceived(channel, message, sender) {
EntityViewer.queryOctree();
print("EBL RECEIVED A MESSAGE FROM ENTITY: " + message);
var entityID = JSON.parse(message).id;
var soundData = getEntityCustomData(SOUND_DATA_KEY, entityID);
print("SOUND DATA " + JSON.stringify(soundData))
if (soundData && soundData.url) {
}
}
Messages.subscribe(MESSAGE_CHANNEL);
Messages.messageReceived.connect(messageReceived);