Click to See Complete Forum and Search --> : window.setInterval
ahobday
03-06-2003, 05:54 AM
I am trying to embed a WMP file directly into an HTML page, hiding the default WMP skin and controls and displaying only those i want to show. The microsoft site has provided me with most of the information i need including the script below which shows the elapsed time of the media clip in hours:minutes:seconds format.
However i can not get the script to work as i do not understand the phrase "An HTML TEXT element named MyText was created to display the current position". How do i display the value of 'MyText' so that it is refreshed every second?
From the microsoft site:
The following JScript example starts an HTML timer that displays the current position of the media file at one-second intervals. An HTML TEXT element named MyText was created to display the current position. The player object was created with ID = "Player".
var timer = window.setInterval("MyText.value = Player.controls.currentPositionString",1000);
gil davis
03-06-2003, 06:14 AM
They want you to put a text box somewhere on the page and call it "MyText":<input type="text" name="MyText">(this breaks HTML rules that require form elements to be inside form tags, but we are talking about Micro$oft)
ahobday
03-06-2003, 06:17 AM
Sorry i should have explained that i had already tried that without any success. I get a JS error 'MyText' is undefined.
gil davis
03-06-2003, 06:41 AM
You should have also posted a link, or at least the code you have already tried.
If you attempt to access an object before it is created, you will get an error. HTML is an interpreter, not a compiler. Most things have to be declared prior to being accessed.
ahobday
03-06-2003, 06:52 AM
I am new to JS. Could you explain in more depth! How do i declare the text field MyText?
Here is the code i am using:
<HTML>
<HEAD>
<TITLE>Embed Video</TITLE>
</HEAD>
<BODY>
<SCRIPT>
function StartMeUp(url) {
document.Player.URL = url;
document.Player.controls.play();
}
function setVolume(vol){
Player.settings.volume = vol;
}
function ShutMeDown ()
{
Player.controls.stop();
}
var timer = window.setInterval("MyText.value = Player.controls.currentPositionString",1000);
</SCRIPT>
<span id="mediaPlayer" style="position:absolute; left:0px; top:0px; z-index:1">
<OBJECT ID="Player" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
<PARAM NAME="uiMode" VALUE="mini"/>
</OBJECT>
<p>
<FORM>
<INPUT TYPE="BUTTON" VALUE="Play Lo" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=DC291874-8271-4A32-8580-4B4423A04281')"/>
<INPUT TYPE="BUTTON" VALUE="Play Med" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=DCC22A4C-A0D9-48A2-B557-42A9515EA972')"/>
<INPUT TYPE="BUTTON" VALUE="Play Hi" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=670FB249-295B-4077-99CD-5474BA8D6E01')"/>
<INPUT TYPE="BUTTON" VALUE="Stop" ONCLICK="ShutMeDown()"/>
<!-- Create an HTML CHECKBOX control. -->
<INPUT TYPE = "CHECKBOX" ID = MUTE onClick = "
/* Use the CHECKBOX state to set
the mute property. */
Player.settings.mute = MUTE.checked;">
<INPUT TYPE="BUTTON" VALUE="+" ONCLICK="setVolume('80')"/>
<INPUT TYPE="BUTTON" VALUE="-" ONCLICK="setVolume('10')"/>
<input type="text" name="MyText">
<INPUT TYPE = "BUTTON" ID = "VERSION" VALUE = "Show Version"
onClick = "
/* Build the message containing the version info. */
var message = 'Windows Media Player Version: ';
message += '\n';
message += Player.versionInfo;
/* Display the message box. */
alert(message);
">
</FORM>
</p>
</span>
</BODY>
</HTML>
gil davis
03-06-2003, 06:59 AM
<HTML>
<HEAD>
<TITLE>Embed Video</TITLE>
<SCRIPT>
function StartMeUp(url) {
document.Player.URL = url;
document.Player.controls.play();
}
function setVolume(vol){
Player.settings.volume = vol;
}
function ShutMeDown ()
{
Player.controls.stop();
}
function init() {
timer = window.setInterval("document.mf.MyText.value = Player.controls.currentPositionString",1000);
}
</SCRIPT>
</HEAD>
<BODY onload="init()">
<span id="mediaPlayer" style="position:absolute; left:0px; top:0px; z-index:1">
<OBJECT ID="Player" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
<PARAM NAME="uiMode" VALUE="mini"/>
</OBJECT>
<p>
<FORM name="mf">
<INPUT TYPE="BUTTON" VALUE="Play Lo" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=DC291874-8271-4A32-8580-4B4423A04281')"/>
<INPUT TYPE="BUTTON" VALUE="Play Med" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=DCC22A4C-A0D9-48A2-B557-42A9515EA972')"/>
<INPUT TYPE="BUTTON" VALUE="Play Hi" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=670FB249-295B-4077-99CD-5474BA8D6E01')"/>
<INPUT TYPE="BUTTON" VALUE="Stop" ONCLICK="ShutMeDown()"/>
<!-- Create an HTML CHECKBOX control. -->
<INPUT TYPE = "CHECKBOX" ID = MUTE onClick = "
/* Use the CHECKBOX state to set the mute property. */
Player.settings.mute = MUTE.checked;">
<INPUT TYPE="BUTTON" VALUE="+" ONCLICK="setVolume('80')"/>
<INPUT TYPE="BUTTON" VALUE="-" ONCLICK="setVolume('10')"/>
<input type="text" name="MyText">
<INPUT TYPE = "BUTTON" ID = "VERSION" VALUE = "Show Version" onClick = "
/* Build the message containing the version info. */
var message = 'Windows Media Player Version: ';
message += '\n';
message += Player.versionInfo;
/* Display the message box. */
alert(message);
">
<input type="text" name="MyText" value="" size=50>
</FORM>
</p>
</span>
</BODY>
</HTML>
ahobday
03-06-2003, 07:18 AM
Thanks for your reply. I can see your method and i no longer get the JS error but the text field is not displaying the value. Do you have any suggestions?
gil davis
03-06-2003, 07:54 AM
<HTML>
<HEAD>
<TITLE>Embed Video</TITLE>
<SCRIPT>
var timer = null;
function StartMeUp(url) {
document.Player.URL = url;
document.Player.controls.play();
}
function setVolume(vol){
document.Player.settings.volume = vol;
}
function ShutMeDown () {
document.Player.controls.stop();
}
function init() {
timer = setInterval("document.mf.MyText.value = document.Player.controls.currentPositionString;", 1000);
}
</SCRIPT>
</HEAD>
<BODY onload="init()">
<span id="mediaPlayer" style="position:absolute; left:0px; top:0px; z-index:1">
<OBJECT ID="Player" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
<PARAM NAME="uiMode" VALUE="mini"/>
</OBJECT>
<FORM name="mf">
<INPUT TYPE="BUTTON" VALUE="Play Lo" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=DC291874-8271-4A32-8580-4B4423A04281')"/>
<INPUT TYPE="BUTTON" VALUE="Play Med" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=DCC22A4C-A0D9-48A2-B557-42A9515EA972')"/>
<INPUT TYPE="BUTTON" VALUE="Play Hi" ONCLICK="StartMeUp('http://mcms-delivery.virtuebroadcasting.com/deliverMedia.asp?id=670FB249-295B-4077-99CD-5474BA8D6E01')"/>
<INPUT TYPE="BUTTON" VALUE="Stop" ONCLICK="ShutMeDown()"/>
<!-- Create an HTML CHECKBOX control. -->
<INPUT TYPE = "CHECKBOX" ID = MUTE onClick = "
/* Use the CHECKBOX state to set the mute property. */
Player.settings.mute = MUTE.checked;">
<INPUT TYPE="BUTTON" VALUE="+" ONCLICK="setVolume('80')"/>
<INPUT TYPE="BUTTON" VALUE="-" ONCLICK="setVolume('10')"/>
<input type="text" name="MyText" value="" size=50>
<INPUT TYPE = "BUTTON" ID = "VERSION" VALUE = "Show Version" onClick = "
/* Build the message containing the version info. */
var message = 'Windows Media Player Version: ';
message += '\n';
message += Player.versionInfo;
/* Display the message box. */
alert(message);
">
</FORM>
</span>
</BODY>
</HTML>
ahobday
03-06-2003, 09:21 AM
All working, thanks for all your help.