0

I have a problem with the audio on my page, everything is fine on the first load but when I reload it does not sound, thanks for your support

this is the HTML code:

<body>
    <audio autoplay loop id="bg-musica">
        <source src="/media/audio/quazar-city.mp3" type="audio/mp3">
        <source src="/media/audio/quazar-city.ogg" type="audio/ogg">
    </audio>
    <form>
        <fieldset>
            <legend>Sonido</legend> 
            <label for="">Musica</label>
            <input type="range" name="" id="barra-volumen" min="0" max="1" step="0.1">
            <label for="mute">Mute <input  type="checkbox" name="mute" id="mute"></label>
        </fieldset>
    </form>

and this my JS

//volume control
const $musica = document.getElementById("bg-musica");
const $barra = document.querySelector('#barra-volumen')

$barra.addEventListener("change",function(ev){  
    $musica.volume = ev.currentTarget.value;    
  },true);

//muted and unmuted (opciones)
 const $mute = document.querySelector('#mute')
 $mute.addEventListener("change", mutePlay, false);
 
 function mutePlay() {
    let checked = $mute.checked;
   if(checked){
    $musica.volume = 0;
   }else {
    $musica.volume = 1;
   }
 }

sorry for my english, Im spanish speaker, and thanks again :)

6y443v3r
  • 3
  • 2
  • Does this answer your question? [HTML5 Video Autoplay not working correctly](https://stackoverflow.com/questions/16965170/html5-video-autoplay-not-working-correctly) (This question is about video's instead of audio, but the same answer applies.) See also https://developer.chrome.com/blog/autoplay/ – Ivar Oct 01 '22 at 22:51
  • hi, no, in this question use 'autoplay=true' I think this is wrong but in my case I use autoplay correctly but I see that in the console my file is not downloaded at any time only on the first load, is that It is normal? – 6y443v3r Oct 01 '22 at 23:16

0 Answers0