1

I'm inserting an <audio> tag into a page. This works fine in Chrome and Safari on Mac, but on both Chrome and Safari in Windows the tag is inserted but the audio never plays. I've stripped the code down to the minimum, and it's now ridiculously simple. I just have no idea why Windows is being difficult.

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>
            test
        </title>
        <script type="application/x-javascript" src="js/jquery-1.4.2.min.js" charset="utf-8"></script>
    </head>
    <body>
        <script type="application/x-javascript">
        $('body').html('<audio src="./audio/myfile.mp3" autoplay></audio>');
        </script>
    </body>
</html>

Interestingly, if I remove all JS and just insert the <audio> tag into the <body>, Chrome Win works but Safari Win still doesn't. Kind of a secondary question, but does Safari Win require QuickTime (not currently installed) in order to use the <audio> tag?

ggutenberg
  • 6,880
  • 8
  • 39
  • 48

1 Answers1

1

does Safari Win require QuickTime (not currently installed) in order to use the tag

Yes it does.

vbence
  • 20,084
  • 9
  • 69
  • 118
  • 1
    Well that solved half the problem. The other half (Chrome) I solved by calling .play() on the ` – ggutenberg Mar 29 '11 at 02:24
  • It kinda makes sense. When the tag was inserted by a script it can be easily started by the script. Currently there are no issues cocerning autoplay behaviour, I suggest you create one, that way you can ensure if this is indeed expected bahaviour of just a glitch. – vbence Mar 29 '11 at 08:29
  • @dosboy I never knew HTML5 depended on scripts for working components... I wonder how that would affect some unknown place that have no scripts, if that even exists. – cregox Apr 15 '11 at 21:14
  • @Cawas We are talking about elements **inserted by scripts**. At that point you can safely assume scripting is enabled. – vbence Apr 16 '11 at 08:51
  • vbence forget script enabled - that's a choice who's dealing with it wanted to do. Also ` – cregox Apr 16 '11 at 15:59
  • @Cawas The question was about `autoplay` behavior when the *element is inserted by a script*. – vbence Apr 16 '11 at 18:33
  • 1
    @Cawas They have the `controls` attribute, so in theory you can access multimedia functionality without scripting. So your *weird device* has the green light :) – vbence Apr 17 '11 at 08:56