stopping sound injector if sound was looping

This commit is contained in:
ericrius1 2016-02-04 17:57:25 -08:00
parent f6a091b941
commit 9b0e20d82b
2 changed files with 21 additions and 8 deletions

View file

@ -19,7 +19,7 @@ var DEFAULT_SOUND_DATA = {
};
var MIN_PLAY_INTERVAL = 0.2;
var UPDATE_TIME = 100;
var UPDATE_TIME = 2000;
var EXPIRATION_TIME = 5000;
var soundEntityMap = {};
@ -54,17 +54,28 @@ function handleActiveSoundEntities() {
if (soundProperties.timeWithoutAvatarInRange > EXPIRATION_TIME) {
// An avatar hasn't been within range of this sound entity recently, so remove it from map
print("NO AVATARS HAVE BEEN AROUND FOR A WHILE SO REMOVE THIS SOUND FROM SOUNDMAP!");
// If the sound was looping, make sure to stop playing it
if (soundProperties.loop) {
print ("STOP SOUND INJECTOR!!");
soundProperties.soundInjector.stop();
}
delete soundEntityMap[soundEntity];
print("NEW MAP " + JSON.stringify(soundEntityMap));
} else {
// If this sound hasn't expired yet, we want to potentially play it!
if (soundProperties.readyToPlay) {
var newPosition = Entities.getEntityProperties(soundEntity, "position").position;
Audio.playSound(soundProperties.sound, {
volume: soundProperties.volume,
position: newPosition,
loop: soundProperties.loop
});
if (!soundProperties.soundInjector) {
soundProperties.soundInjector = Audio.playSound(soundProperties.sound, {
volume: soundProperties.volume,
position: newPosition,
loop: soundProperties.loop
});
} else {
soundProperties.soundInjector.restart();
}
soundProperties.readyToPlay = false;
} else if (soundProperties.loop === false && soundProperties.interval !== -1) {
// We need to check all of our entities that are not looping but have an interval associated with them
@ -82,6 +93,7 @@ function handleActiveSoundEntities() {
}
}
function handleFoundSoundEntities(entities) {
entities.forEach(function(entity) {
var soundData = getEntityCustomData(SOUND_DATA_KEY, entity);
@ -121,7 +133,8 @@ function handleFoundSoundEntities(entities) {
soundEntityMap[entity] = soundProperties;
}
} else {
//If this sound is in our map already, we want to reset timeWithoutAvatarInRange
//If this sound is in our map already, we want to reset timeWithoutAvatarInRange
// Also we want to check to see if the entity has been updated with new sound data- if so we want to update!
soundEntityMap[entity].timeWithoutAvatarInRange = 0;
}
}

View file

@ -20,7 +20,7 @@ var userData = {
soundKey: {
url: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove.wav",
volume: 0.3,
loop: false,
loop: true,
interval: 2000,
intervalSpread: 1000
}