Update data with Sound Alert

0

In this script down it keeps updating the div and showing a counter

WhatIwantedisthatifthereisanychangeinthenumber,playingaSound"An Alarm" only I have no knowledge of javascript if someone can help me will help me a lot

counter_mapa.php

 $sql1 = "SELECT COUNT(*) AS total1 FROM agenda_saidas where id_transfer1 = '1' ";
 $resultado1 = mysql_query($sql1) or die ("Erro na consulta1");
 $linha1 = mysql_fetch_assoc($resultado1);
 $cancel_solicitado = $linha1['total1'];

List.php

 <div id="latestData"></div>
 <script src="http://code.jquery.com/jquery-latest.js"></script><script>$(function(){functiongetContadorMapa(){$.get("includes/principal/contador_mapa.php", function (result) {
        $('#latestData').html(result);
    });
  }

  getContadorMapa();
  setInterval(getContadorMapa, 20000);
  });

  </script>
    
asked by anonymous 13.06.2017 / 03:54

1 answer

3

Just use play() , nor do you need JQuery, if using JQuery use .trigger('play') .

First define the audio that will trigger:

<audio id="notificacao" preload="auto">
  <source src="http://soundbible.com/grab.php?id=2154&type=mp3"type="audio/mpeg">
</audio>
  

This audio is just an example, it is from the SoundBible , created by Daniel Simion, is subject to some license terms, review them before using them if you wish.

Then just use:

$('#notificacao').trigger('play');

If not, in VanillaJS :

document.getElementById('notificacao').play();

Try:

i = 1;

setInterval(function() {

  $('x-contador').text(5 - i);

  if (i === 5) {
    $('#notificacao').trigger('play');
    i = 0;
  }

  i++;

}, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><audioid="notificacao" preload="auto">
  <source src="http://soundbible.com/grab.php?id=2154&type=mp3"type="audio/mpeg">
</audio>

<x-contador></x-contador>
    
13.06.2017 / 04:35