Update data with Audible Alert

Asked

Viewed 2,108 times

0

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

inserir a descrição da imagem aqui

What I wanted is that if there is any change in the number, playing a Sound "An Alarm" only that I have no knowledge of javascript if someone can help me will help me a lot

counter_map.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 () {
 function getContadorMapa() {
    $.get("includes/principal/contador_mapa.php", function (result) {
        $('#latestData').html(result);
    });
  }

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

  </script>

1 answer

4

Just use the play(), nor need Jquery, if using Jquery use .trigger('play').

First set 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 one example, it is from Soundbible, created by Daniel Simion, you are subject to some license terms, review them before using them, if you so wish.


Then just use it:

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

If not, in the 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>

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

<x-contador></x-contador>

  • Almost... more I wanted when a new number arrived there yes play sound

  • Suffice it to compare, $('#latestData').html() != result){ // .play() // }, without the HTML of the page it is a little difficult to know how the elements are inserted, but generically this is it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.