Home > Web Front-end > Front-end Q&A > What should I do if html5 music cannot be loaded?

What should I do if html5 music cannot be loaded?

藏色散人
Release: 2023-01-06 11:38:18
Original
2798 people have browsed it

The solution to the problem that html5 music cannot be loaded: 1. Open the corresponding html file; 2. Check the HTML5 audio tag code; 3. Through a piece of js code "function toggleSound() {var music=document.getElementById( "vd");console.log(music);console.log(music.paused);if () {...}" can solve the playback problem.

What should I do if html5 music cannot be loaded?

#The operating environment of this tutorial: Windows 10 system, HTML5 version, Dell G3 computer.

html5 What should I do if the music cannot be loaded?

Solving the problem that HTML5 audio tags cannot be played

Let’s talk about some attributes of the audio tag first

Its attributes:

autoplay autoplay If it appears This property causes the audio to be played as soon as it is ready.

controls controls If this attribute appears, displays controls, such as a play button, to the user.

loop loop If this attribute is present, playback will restart whenever the audio ends.

muted muted Specifies that the video output should be muted.

preload preload If this attribute appears, the audio will be loaded when the page is loaded and prepared for playback. If "autoplay" is used, this attribute is ignored.

src url The URL of the audio to play.

Sometimes after adding the autoplay attribute, we find that it still cannot play automatically. We can add a js code to solve the problem:

function toggleSound() {
            var music = document.getElementById("vd");//获取ID  
                console.log(music);
                console.log(music.paused);
            if (music.paused) { //判读是否播放  
                music.paused=false;
                music.play(); //没有就播放 
            }         
        }
setInterval("toggleSound()",1);
Copy after login

Recommended learning: "HTML5 Video Tutorial"

The above is the detailed content of What should I do if html5 music cannot be loaded?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template