W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2012

[whatwg] HTML Audio Element removal from DOM

From: Michael A. Puls II <shadow2531@gmail.com>
Date: Wed, 18 Jan 2012 00:54:30 -0500
Message-ID: <op.v79mo4go1ejg13@vertiform346>
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
Received on Tuesday, 17 January 2012 21:54:30 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:10 UTC