This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

play beep on specific plan
#1
Hello colleagues, my idea is to be able to reproduce a beep (notification sound) on a specific plan, with a group address. when its state is 1, it reproduces the sound, the problem is what reproduces on all pages and must be in one



Adjunto el código javascript

Code:
12345678910111213141516171819202122
$(function(){    var context= new AudioContext();   function jsNota(frecuencia){         var o= context.createOscillator();         g=context.createGain();         o.connect(g);         o.type="sine";         o.frequency.value=frecuencia;         g.connect(context.destination);         o.start(0);         g.gain.exponentialRampToValueAtTime(0.00001,context.currentTime +1.5);     } grp.listen('1/1/1', function(object, state) {     if (state == 'value' && object.value ) {       jsNota(1174.659, function() {       });     }   }, true);     });

Gracias
Reply
#2
Hi,

Just add a extra condition:
Code:
123
if (currentPlanId == 1){   //your code }
Here is also a code i use if the sound must be repeated until the object is false
Code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
$(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);    });
BR,

Erwin
Reply
#3
thank you very much Erwin, worked perfectly
Reply


Forum Jump: