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.

sound on Win/PC and Android/Tablet
#21
(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:
  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);
  }
});


Great! Thank you so much. And best wishes!


Peppe
Reply


Messages In This Thread
RE: sound on Win/PC and Android/Tablet - by gdimaria - 24.12.2020, 10:26

Forum Jump: