...

View Full Version : Video player using JS and ActiveX



Cybersky
02-03-2004, 03:54 AM
Hi there!

I am trying to get the following script to work for a certain .avi file (or the like) under a controlled fashion.
As far as I know it should work but... it displays no video.

Can any one, please, tell me what's wrong?
***********************************************

<script language="JavaScript">
<!--
function play() {
avibutton.mouseoverfrstart=0;
avibutton.mouseoverfrend=16;
}

function stop() {
avibutton.mouseoverfrstart=0;
avibutton.mouseoverfrend=0;
}

//-->
</script>

</head>

<body>
<h1>Watch the video.</h1><p />

<object id="avibutton" width="160" height="120">
<param name="url" value="file.avi">
<param name="defaultfrstart" value="0">
<param name="defaultfrend" value="0">
<param name="mouseoverfrstart" value="0">
<param name="mouseoverfrend" value="15">
<param name="focusfrstart" value="0">
<param name="focusfrend" value="15">
<param name="downfrstart" value="0">
<param name="downfrend" value="15">
</object>

<form name="form">
<input name="Play" type="button" value="Play" onclick="play()">
<input name="Stop" type="button" value="Stop" onclick="stop()">
</form>

</body>

************************************************

Thanks in advance.
Cybersky :confused:

swmr
02-04-2004, 06:25 PM
The short answer is: you need to supply a classid for the object.

Beyond that, the availability of automation depends on:

1. If the class is registered on your system.
2. If the class supports automation & can be late-bound.

I've created an HTA to test whether a given classid is an object available for automation.
If you'd like try it out, just copy the following code, and save it as "classTest.hta" (or whatever *.hta):



<html>
<head>
<title>Class Test</title>
<HTA:APPLICATION SINGLEINSTANCE = "yes" />

<script type="text/JScript">

function oTest(F){

F.ProgId.value = "";
F.viProgId.value = "";

var val, P, isValid, wsS;

val = F.clsid.value;

P = /[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}/i;

isValid = P.test(val);

if(+isValid < 1 || val.length > 36){
alert("The value submitted is not a valid classid.");}

else{
wsS = new ActiveXObject("WScript.Shell");
try{
wsS.RegRead("HKCR\\CLSID\\{" + val +"}\\");
isAutomation(F, wsS, val);
}
catch(e){
alert("This class is not registered on your system.");
}

}}

function isAutomation(F, wsS, val){
var pId, isObj;

try{
pId = wsS.RegRead("HKCR\\CLSID\\{" + val + "}\\ProgID\\");

isObj = typeof(new ActiveXObject(pId)) == "object";

+isObj < 1 ? alert("Automation error!" + "\n" + "cannot late-bind: "+ pId) :
isVIProgId(F, wsS, val, pId);
}
catch(e){
alert("Error: no ProgID found." + "\n" +
"Automation is not available for this class.");}
}

function isVIProgId(F, wsS, val, pId){
var vpId;
try{
vpId = wsS.RegRead("HKCR\\CLSID\\{" + val + "}\\VersionIndependentProgID\\");
F.viProgId.value = vpId;
}
catch(e){
F.viProgId.value = "not available";
}
finally{
alert("Success!" + "\n" + "Automation is available for this class.");
F.ProgId.value = pId;}
}
</script>

<style type="text/css">
body{
background:threedface;
}
h4{text-align:center;}
form{
text-align:center;white-space:nowrap;
}
fieldset{
margin:20px;padding:10px;
}
label{
color:activecaption;
}
button{color:activecaption;vertical-align:middle;
}
input{
vertical-align:middle;text-align:center;
margin:5px;
}
.out{
background:threedface
}
</style>
</head>

<body onload="document.cTest.clsid.select();">

<h4>This HTA will read the system Registry
(<small>HKEY_CLASSES_ROOT</small>):</h4>

<form name="cTest">
<fieldset>
<legend>Input</legend>
<label>classid:</label><input name="clsid" size="44"
value="0002DF01-0000-0000-C000-000000000046" maxlength="36">
<button onclick="oTest(this.form)">Automation Test</button>
</fieldset>
<fieldset>
<legend>Output</legend>
<label>ProgId:</label><br><input name="ProgId" size="75" readonly class="out">
<br><br>
<label>VersionIndependentProgId:</label><br><input name="viProgId" size="75"
readonly class="out">
</fieldset>
</form>

</body>
</html>


edit >> Fixed code to clear output on submit.

edit2 >> Forgot to make pattern case insensitive. :D

jkd
02-04-2004, 07:24 PM
This has nothing to do with DOM Scripting.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum