[thelist] Can't get embedded media to play with JavaScript

Peter-Paul Koch pp.koch at gmail.com
Fri Jul 20 12:20:15 CDT 2007

> On an AJAX-heavy application, sometimes sound effects are required. To do
> this, on page load, a couple of WAV files are embedded into the HTML
> document from an external JS file using DOM. I'm using EMBED here because
> this should be cross-platform, and I don't want to force a particular
> player. Who knows what plugin the visitor is using to play back a WAV file,
> it could be WMP, QuickTime, RealPlayer, and who knows what else. So I'll let
> the browser figure it out for itself.

Yes, that's all correct.

> doPlay should work if RealPlayer is used, run should work for Windows Media
> Player, and play() should work in all other situations. For some reason,
> nothing happens in FF or IE7 on Vista.

As far as I know RealPlayer cannot be accessed by JavaScript in IE,
while Windows Media Player can be accessed by JavaScript *only* in IE.

I advise you to create a certain embed at the moment you need it, and
set autostart to true.   If the sound has to play again, create a new
embed. If you wish you can destroy the embeds after X seconds have
passed. (Reading out its status by JavaScript has the same access
problems as playing it, so destroying it after X time has passed is
your only cross-browser option.)

ppk, freelance web developer

More information about the thelist mailing list