24.12.2020, 08:46
This should do what you want. You can change the interval (it is 2000 milliseconds now) if needed.
Code:
var 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);
}
});