Front-end learning audio video and its solution to the problem that Google Chrome cannot play automatically (3)

Table of contents

1. Audio and video applications:

 2. Solutions to the problem that audio and video cannot be played on Google Chrome

Method 1: Type the js code in the picture below into the code

Method 2: Website Settings


1. Audio and video applications:

Type in vscode

 Open the browser and the audio and video will play automatically.

 2. Solutions to the problem that audio and video cannot be played on Google Chrome

Method 1: Type the js code in the picture below into the code

<script type="text/javascript"> 
    window.onload = function(){ 
          
   
             setInterval("toggleSound()",1); 
        } 

    function toggleSound() { 
          
   
                var music = document.getElementById("music");//Get ID   
                if (music.paused) { 
          
    //Determine whether to play   
                    music.paused=false; 
                    music.play(); //Play if not 
                }     
        } 
</script>

Set an id for the audio and use the method to implement automatic playback:

 Click the page audio and it will automatically play.

Method 2: Website Settings

Click on website settings,

 Click the sound option in more content settings and add the URL to automatically play the audio.

 If there are any errors in the content, you are welcome to point them out in the comment area. Thank you for browsing.

Guess you like

Origin blog.csdn.net/qq_53866767/article/details/130933328