25.10.2019, 18:35
(This post was last modified: 25.10.2019, 18:40 by Erwin van der Zwart.)
Hi,
Just add a extra condition:
Here is also a code i use if the sound must be repeated until the object is false
BR,
Erwin
Just add a extra condition:
Code:
if (currentPlanId == 1){
//your code
}
Code:
$(function(){
var locked;
var ctx = new(window.AudioContext || window.webkitAudioContext || window.mozAudioContext || window.oAudioContext || window.msAudioContext);
var Beeping;
function beep(duration, freq, vol, cb) {
var osc = ctx.createOscillator();
osc.frequency.value = freq;
var volumeNode = ctx.createGain();
volumeNode.gain.value = (vol/1000);
osc.connect(volumeNode);
volumeNode.connect(ctx.destination);
osc.start ? osc.start(0) : osc.noteOn(0);
setTimeout(function () {
osc.disconnect();
if (typeof cb == "function") {
cb();
}
}, duration);
}
/* beep each time value is true note that 3rd listen parameter must be set to true to execute the callback each time new value arrives otherwise callback is executed only when value changes */
function startbeep(){
var ChromeDelay = 0;
if (document.hidden && !!window.chrome){
ChromeDelay = 1500;
}
setTimeout(function(){
if (!locked) {
locked = true;
// duration , freq
beep(300, 1500, 50, function() {
locked = false;
});
}
}, ChromeDelay);
}
// Function to start beep interval
function StartBeepTimer(){
// Jump to correct page
//showPlan(3);
// Set delay timer to start after x seconds
setTimeout(function(){
// Start feedback polling every second
if (!Beeping) {
// Run once to bypass the first delay
startbeep();
Beeping = setInterval(function(){ startbeep(); }, 2000);
}
}, 50); // Set higher value then 50 for extra delay after stop and start beep
}
// Function to stop beep interval
function StopBeepTimer(){
// Stop feedback polling every second
if (Beeping) {
clearInterval(Beeping);
}
Beeping = null;
}
// Creta elistener to start audio beep
grp.listen('21/0/1', function(object, state) {
if (state == 'value' && object.value ) {
StartBeepTimer();
} else if( state == 'value' && object.value == false){
StopBeepTimer();
}
}, true);
});
Erwin