On Tue, 17 Jan 2012 16:19:37 -0500, Charles Pritchard <[email protected]> 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

Reply via email to