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.
#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);
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!