HTML5 simple implementation of several methods to add background music

Time:2021-9-21

Two methods are recommended here, that is, two tags < embedded > or < audio >

Common < audio > + CSS layout hidden player website is more practical!

<!DOCTYPE html>
<html>
<head>
    < title > HTML5 add music < / Title >
    <meta charset="utf-8">
   
< embedded SRC = "C: \ users \ pride and Prejudice \ music \ Ling Yuan Yousa - Acacia. Mp3" hidden = "flash" autostart = "true" loop = "true" >

<!-- The embedded tag is written under the title tag in < head > -- >
explain:
1. SRC no doubt writes the path
2. Use hidden = "true" to hide the music playback button. On the contrary, use hidden = "false" to turn on the music playback button.
3. Use autostart = "true" to indicate that the page will be played automatically after loading.
4. Use loop = "true" to indicate loop playback. If you want to play only once, it is: loop = "false"

</head>

<body>
<audio autoplay="autoplay" loop="loop" preload="auto" controls="controls"
            SRC = "C: \ users \ pride and Prejudice \ music \ Ling Yuan Yousa - lovesickness. Mp3" >       
</audio>
explain:
1. With autoplay = "autoplay", the background music will be played automatically immediately after the audio web page is opened.

2. Use controls = "controls" to display controls, such as play buttons, in the page.

3. Use "loop =" loop "to repeat the background music.

4. If preload = "auto" is used, the audio will be loaded while the page is loaded and ready for playback.

5. Use SRC = "" to save the background music in "", such as SRC = "".

Note: if you want to hide the play button, use the following statement:

Directly use the display of CSS to control the display of Audio Tags:
<style type="text/css">
 audio{
         display: none;
     }
</style>
</body>
</html>

There is also a < bgSound > tag:

< bgSound > tag is IE

< embedded > for others

General usage:


<bgsound src=" " autostart="true" loop="false" />

<embed src=" " autostart="true" loop="false" />

I’ve been doing bgSound for a long time, but there’s no sound. Possible reasons: < bgSound > tags won’t be read directly in IE kernel, so EM

Solution: when it is judged that the IE kernel is loaded, the < embedded > tag should be in front of < bgSound >, and the automatic playback should be set to autostart = “false”;

This is the end of this article on how to add background music in HTML5. For more information about adding background music in HTML5, please search for previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!

Recommended Today

Swift advanced (XV) extension

The extension in swift is somewhat similar to the category in OC Extension can beenumeration、structural morphology、class、agreementAdd new features□ you can add methods, calculation attributes, subscripts, (convenient) initializers, nested types, protocols, etc What extensions can’t do:□ original functions cannot be overwritten□ you cannot add storage attributes or add attribute observers to existing attributes□ cannot add parent […]