Adding sound to a page using jquery

What is the preferred method for adding sound to a page using jquery?

I am considering using jPlayer, but I have my doubts about it. Depending on the messages displayed on the screen, I need to adjust the sound.

Thanks in advance.

+4
source share
2 answers

Personally, I find the random sound on the website really annoying, but here you go:

<audio> <source src="audio/audio.mp3"></source> <source src="audio/audio.ogg"></source> HTML5 Needed </audio> <script> var audio = $("audio")[0]; audio.play(); </script> 

or something like:

 $("<audio></audio>").attr({ 'src':'audio/something.mp3', 'volume':0.4, 'autoplay':'autoplay' }).appendTo("body"); 

Both of these examples use HTML5, but with minor modifications, you can use flash memory to play audio.

+4
source

Personally, I prefer jPlayer and use it heavily. But you might think about Soundmanager. http://www.schillmania.com/projects/soundmanager2/

0
source

Source: https://habr.com/ru/post/1383442/


All Articles