24.12.2020, 10:26
(24.12.2020, 08:46)admin Wrote: This should do what you want. You can change the interval (it is 2000 milliseconds now) if needed.
Code:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051var interval; // Function to play audio by URL function Play_Audio(url){ //console.log(OS_Version) if (OS_Version === 'Android' || OS_Version === 'U.Motion' ){ //alert(OS_Version); snd.src = url; snd.pause(); sndcurrentTime = 0; //snd.load(); snd.play(); } else { request.open("GET", url, true); request.responseType = "arraybuffer"; request.onload = function(){ ctx.decodeAudioData(request.response, onDecoded); } function onDecoded(buffer){ var bufferSource = ctx.createBufferSource(); bufferSource.buffer = buffer; bufferSource.connect(ctx.destination); bufferSource.start(); } request.send(); } }; // Function to create event listeners function CreateListeners(groupaddr,url){ // Make event listener to object if (typeof grp != 'undefined') { grp.listen(groupaddr, function(object, state) { var value = object.value; var enabled = grp.getvalue('32/2/1'); clearInterval(interval); if (state == 'value' && value == 1 && enabled) { Play_Audio(url); interval = setInterval(function() { Play_Audio(url); }, 2000); } }, true); } } // Start creating listeners for (var i in AudioTable) { CreateListeners(AudioTable[i].address,AudioTable[i].url); } });
Great! Thank you so much. And best wishes!
Peppe