HTML | DOM Audio play() Method

The HTML DOM Audio play() method is used to start playing the current audio. To use the Audio play() method, one must use the controls property to display the audio controls such as play, pause, seeking, volume, etc, attached to the audio. This method is used together with the pause() method.

Syntax:

audioObject.play()

Return Value:

  • No return value

Parameter:

  • No Parameter

Example:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        DOM Audio play( ) Method
    </title>
</head>
  
<body style="text-align:center">
  
    <h1 style="color:green"
    GeeksforGeeks 
    </h1>
    <h2 style="font-family: Impact"
    Video play() method 
    </h2>
    <br>
    <audio id="idAudio">
        <source src=
                type="audio/ogg">
        <source src=
                type="audio/mpeg"
      Your browser does not support the audio element.
    </audio>
  
    <p>To play the Audio, click the "Play Audio" button.</p>
  
    <button onclick="play_Audio()" type="button">Play Audio</button>
    <button onclick="pause_Audio()" type="button">Pause Audio</button>
  
    <script>
        var GFG = document.getElementById("idAudio");
  
        function play_Audio() {
            GFG.play();
        }
  
        function pause_Audio() {
            GFG.pause();
        }
    </script>
  
</body>
  
</html>

chevron_right


Output:

Supported Browsers:

  • Chrome
  • Mozilla Firefox
  • Internet Explorer 9.0
  • Opera
  • Safari

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.