Re: Some issues with player control, keep resizing automatically.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Neil,
Thanks it helps, the trick is happened that as soon as I moved code for
attachEvent() after appending child control , everyhting started works.
Other code seems do not affecting operation, but I will try play with other
staff and will check how it works with other browsers.

So I only changed:

elWmp.autoStart="-1";
elWmp.attachEvent("onPlayStateChange",PlayState);

________________________^^ should be attachEvent("playstatechange"

elWmp.attachEvent("onresize",trapSize);

________________________^^ should be attachEvent("resize"


elDivPlayer.appendChild(elWmp);


for the code:

elDivPlayer.appendChild(elWmp); //and then after
elWmp.attachEvent("PlayStateChange",PlayState);

for some reason "onresize" event works fine even when attached before (I
guess because it is common browser event) and with "onresize" as a key word .

The player url is assigned much later in a code. First I just opening blank
media platyer and then user choosing url to play, that why you don't see it.


I didn't put all code because there to many other GUI elements, events not
related to media player, that why I didn't bother post it.


"Neil Smith [MVP Digital Media]" wrote:

On Fri, 10 Feb 2006 14:31:18 -0800, "eug_acc"
<eugacc@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:


Here is part of code to create player:

var elWmp=document.createElement("object");
elWmp.classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6";
//elWmp.className="forplayer";
elWmp.uiMode='full';
elWmp.windowlessVideo='true';
elWmp.id='wmp';
elWmp.stretchToFit='true';
elWmp.playCount="1";
elWmp.autoStart="-1";
elWmp.attachEvent("onPlayStateChange",PlayState);

________________________^^ should be attachEvent("playstatechange"

elWmp.attachEvent("onresize",trapSize);

________________________^^ should be attachEvent("resize"


//elWmp.fullScreen='false';
//elWmp.innerHTML=htmlM;
elDivPlayer.appendChild(elWmp);


I'm not sure it works in all browsers, but you may need to attach
those events *after* appending the child to the DOM - before that I'm
not clear that the events are in scope until the object is part of the
DOM.


//obviousely, elDivPlayer created already and it is just container for

OK

player control. //At the end I added elDIvPlayer to document.body

function PlayState()
{
//for now I only would like get laert message
alert(document.all.wmp.playState);

}

I can't get any "error" or any messages at all.

I'm not able to determine from your code, because again you've only
posted part of the code : Where are you setting the player URL and
telling the player to 'play()' ? The playstatechange event is only
triggered when the media player changes playing state. Given the
(modified) code above, that event will never be triggered.

So now we look at the code you've posted. There are several areas in
error which as I requested before, you probe by setting the browser to
report javascript errors.

It's clear you didn't bother doing that, because you would have seen
one of the errors immediately with the code above :

'Can not set property at runtime' (referring to the attempt to set the
classID dynamically on the object). This is documented here, and here

http://msdn.microsoft.com/workshop/author/dhtml/overview/activating_activex.asp
http://karma.nucleuscms.org/item/108

It refers to the fact you can't create an ActiveX object without first
atttaching the parent to the DOM, as I suggested above for the event
handlers.


I changed the code above to a complete set which does work in IE :
================================================

<script language="javascript1.2">
var elWmp;

function loadPlayer() {
var elDivPlayer=document.getElementById("divplayer");
elWmp=document.createElement("object");
elDivPlayer.appendChild(elWmp);
elWmp.width="390";
elWmp.height="250";
elWmp.classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6";
elWmp.uiMode="full";
elWmp.windowlessVideo="true";
elWmp.id="wmp";
elWmp.stretchToFit="true";
elWmp.playCount="1";
elWmp.autoStart="false";
elWmp.URL="falluja.asf";
elWmp.attachEvent("playstatechange",PlayState);
}
function PlayState() {
alert("This is my playstate : "+elWmp.playState);
}
</script>

<div id="divplayer" style="width: 400px; height: 300px; border: 1px
solid #333333; background-color: #FFCC33"></div>

<input type="button" name="playstart" id="playstart" value="Load
Player" onclick="loadPlayer()" />


================================================
That code likely won't work in Firefox, Opera, Safari etc.

Those browsers have no concept of "classID" which is the correct
interpretation of the W3C DOM. You need to specify a
type="video/x-ms-wmv" for video in those browser.

You will need to browser sniff for W3C as opposed to MS DOM support,
because if you set ClassID *and* type for WMP OCX, the browser will
fail with the setting type at runtime error. You specify either MIME
type of the content OR classID depending on browser (probably using
test for document.createImplementation vs document.createElement)


HTH
Cheers - Neil

.



Relevant Pages

  • Re: Some issues with player control, keep resizing automatically.
    ... Here is part of code to create player: ... those events *after* appending the child to the DOM - before that I'm ... Those browsers have no concept of "classID" which is the correct ... You will need to browser sniff for W3C as opposed to MS DOM support, ...
    (microsoft.public.windowsmedia.player.web)
  • Re: hiding logo from displaying when avi file played on webpage
    ... The logo only displays for the version 6.4 player. ... tag, you are forcing the browser to use the 6.4 player ... even with the version 6.4 classID. ...
    (microsoft.public.windowsmedia.player.web)
  • Re: Attributes VS Properties
    ... DOM properties provide a higher-level interface, ... action for the still-popular MS browser. ... I'm asking this because I've read some discussions about Jquery mixing ... DOM scripting library that complicates the hell out of DOM scripting ...
    (comp.lang.javascript)
  • Re: question
    ... player specific manner that's not emulatable by other standards-based ... browser OS combination did not work for sound when embed was used. ... browser/OS combinations support an illegal tag such as embed or any ... a really old IE browser will not support embed. ...
    (alt.html)
  • Re: Hot (but disappointing) news
    ... I don't think that NetSurf would necessarily become "too slow" on older hardware, but it would definitely become slower. ... One big problem is that JavaScript isn't even self-contained in terms of the language, because of its interface to the DOM. ... This means that the JS garbage collector has to worry about DOM objects as well as JS objects. ... Until the browser somehow knows that the listened-for event will never be generated, it can never discard the listener, so it can never discard the associated scope chain. ...
    (comp.sys.acorn.misc)