[whatwg] HTML Audio Element removal from DOM

Michael A. Puls II shadow2531 at gmail.com
Tue Jan 17 21:54:30 PST 2012


On Tue, 17 Jan 2012 16:19:37 -0500, Charles Pritchard <chuck at jumis.com>  
wrote:

> When an <audio> element is removed from the DOM while playing, is that  
> element paused?
> That seems to be the behavior in Chrome. I'm looking for clarification.

It's the behavior in Firefox and Opera too.

In both cases below, the audio is paused when removed from the document.  
When added back it's still paused and when you call play(), it continues  
playing from where it left off.

<!DOCTYPE html>
<html lang="en">
     <head>
         <meta charset="utf-8">
         <title></title>
         <script>
             window.addEventListener("DOMContentLoaded", function() {
                 var player = document.createElement("audio");
                 player.controls = true;
                 player.autoplay = true;
                 player.src = "test.oga";
                 document.body.appendChild(player);
                 setTimeout(function() {
                     document.body.removeChild(player);
                     setTimeout(function() {
                         document.body.appendChild(player);
                         player.play();
                     }, 3000);
                 }, 7000);
             }, false);
         </script>
     </head>
     <body>

     </body>
</html>


<!DOCTYPE html>
<html lang="en">
     <head>
         <meta charset="utf-8">
         <title></title>
         <script>
             window.addEventListener("DOMContentLoaded", function() {
                 var player = document.getElementsByTagName("audio")[0];
                 setTimeout(function() {
                     player = document.body.removeChild(player);
                     setTimeout(function() {
                         player = document.body.appendChild(player);
                         player.play();
                     }, 3000);
                 }, 7000);
             }, false);
         </script>
     </head>
     <body>
         <audio controls autoplay src="test.oga"></audio>
     </body>
</html>

-- 
Michael



More information about the whatwg mailing list