Does not play mp3 sound in HTML

0

I try to integrate an audio into an HTML document but it does not play it.

Code:

<td height="380" colspan="3" valign="middle" class="bb">
  <audio src="noticias/entrevista_radio_14feb2017.mp3"></audio>
</td>

The file is called as the name indicates and I have it inside the "news" folder.

    
asked by omaza1990 09.02.2018 в 15:18
source

2 answers

1

When you put a audio on your web page, it does not start automatically. To start sounding the audio you can use the autoplay attribute:

<td height="380" colspan="3" valign="middle" class="bb">
  <audio src="noticias/entrevista_radio_14feb2017.mp3" autoplay></audio>
</td>

Or you can use JavaScript with the play method of the audio:

<td height="380" colspan="3" valign="middle" class="bb">
  <audio src="noticias/entrevista_radio_14feb2017.mp3" id="miAudio"></audio>
</td>

<script>
document.getElementById("miAudio").play();
</script>
  

Note: the audio should not start on its own, it is something that is not recommended because it can give a bad user experience, and should be avoided.

If after using one of these two options, the audio is still not working, this may happen because the audio file format is not correct. You can see a list of formats and codecs supported by audio and video in this MDN page .

    
answered by 09.02.2018 / 15:47
source
2

You can try this code to have a player appear:

<td height="380" colspan="3" valign="middle" class="bb">
    <audio controls autoplay>
        <source src="noticias/entrevista_radio_14feb2017.mp3" type="audio/mpeg">
        Tu navegador no es compatible para reproducir audio.
    </audio>
</td>
    
answered by 09.02.2018 в 15:36