How does one use JavaScript with the Windows Media Player Plugin?
Hi there.
According to this old MSDN Article it is possible to control the windows media player plugin using javascript.
It provides a series of objects off the object that should perform certain funtions, such as play stop and seek.
It states very clearly in the article that some are not supported; however, none of them seem to be working with the latest version(s?) of Firefox.
I have Firefox 5 installed currently and have not tested in any other version, so I'm not sure when it stopped working.
The video does load and will display properly -- the ability to control it through javascript however, does not work.
i.e.:
var mplay = document.getElementById('myplayer'); mplay.controls.play(); // mplay.controls is undefined
This same code works in Internet Explorer.
Όλες οι απαντήσεις (6)
If you change that second line to
alert(mplay);
Does that display the expected result? If not, are you nesting an EMBED in an OBJECT? I think using the OBJECT's id to get a reference to the EMBED stopped working at some point.
A Ha! Yes, this is indeed the case. Referencing the EMBED object does the trick.
This showed up on what I can only assume is really old generated code. Nothing like checking the appName of Netscape to tweak the eyebrow.
Thanks very much for the prompt response!
Hi i have the same problem but i don't understand your answer.
Can you give me an example how i will nest the EMBED tag to an OBJECT.
This is the code i am using.
<SCRIPT type="text/javascript"> if(-1 != navigator.userAgent.indexOf("MSIE")) { document.write('<OBJECT id="Player" width=320 height=45'); document.write(' classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112"'); document.write(' <param name="AudioStream" value="true">'); document.write(' <param name="Enabled" value="True">'); document.write(' <param name="ClickToPlay" value="false">'); document.write(' <param name="BufferingTime" value="5">'); document.write(' <param name="ShowDisplay" value="False">'); document.write(' <param name="Volume" value="70">'); document.write(' <param name="autoStart" value="true">'); document.write(' <param name="URL" value="http://87.117.197.189:16229">'); document.write(' </OBJECT>'); } else if(-1 != navigator.userAgent.indexOf("Firefox")) { document.write(' <OBJECT id="Player" width=320 height=45'); document.write(' type="application/x-ms-wmp"'); document.write(' <param name="AudioStream" value="true">'); document.write(' <param name="Enabled" value="True">'); document.write(' <param name="ClickToPlay" value="false">'); document.write(' <param name="BufferingTime" value="5">'); document.write(' <param name="ShowDisplay" value="False">'); document.write(' <param name="Volume" value="70">'); document.write(' <param name="autoStart" value="true">'); document.write(' <param name="URL" value="http://87.117.197.189:16229">'); document.write(' </OBJECT>'); } </SCRIPT>
Then i create some simple functions in javascript in order to stop - play - mute the Media player.
<script type="text/javascript"> function StartMeUp () { Player.URL = "http://87.117.197.189:16229"; } function ShutMeDown () { Player.controls.stop(); } function MutePlayer () { Player.settings.mute = true; } </SCRIPT>
The above example plays smoothly at Internet Explorer but is not responses in javascript in Firefox.
Any help please...
Τροποποιήθηκε στις
You should ask this in a forum someplace... I don't see an <embed> in your code. If you have a nested embed object and reference that as "player" it seems to work.
@smartmedia, first, can you verify that the <object> is being written into the page correctly? If you select that part of the page, right-click, and use View Selection Source, you can see whether the <object> has the intended attributes and isn't broken. Please note that for Firefox, you should NOT use classid and you SHOULD have a data attribute set to the URL of the source.
Second, if that all looks good, check Firefox's Error Console (Tools menu) for any errors related to that object. You may want to use the Errors button to filter out the CSS warnings. Anything relevant?
Third, where are you setting the value of Player? Firefox doesn't automatically create a global reference for id's. You would need something like this:
var Player = document.getElementById("Player");
You need to place the URL in a data attribute for Firefox.
document.write(' <OBJECT id="Player" data="http://87.117.197.189:16229" width="320" height="45" type="application/x-ms-wmp">'); document.write(' <param name="AudioStream" value="true">'); document.write(' <param name="Enabled" value="True">'); document.write(' <param name="ClickToPlay" value="false">'); document.write(' <param name="BufferingTime" value="5">'); document.write(' <param name="ShowDisplay" value="False">'); document.write(' <param name="Volume" value="70">'); document.write(' <param name="autoStart" value="true">'); document.write(' </OBJECT>');
Τροποποιήθηκε στις