Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Starting Quicktime Movie Muted

Status
Not open for further replies.

lownoise2

Programmer
May 4, 2005
7
US
My Goal: Start a quicktime movie embedded on a page, but with the sound muted.

The Problem: Can mute sound under user action, but not automatically. Whenever I try to use the SetMute(), I get unidentified errors (which I take to mean that the object is not in a full state of existence, or somesuch).

Enclosed is the HTML/JavaScript, which is mostly copied directly from Apple's examples. But their examples perform all the actions on the movies only under user's initiation, which necessarily happens after the page is all loaded.

My particular addition is the MuteMe script at the end, which attempts to mute one of the movies. This creates an "Unidentified Error" in IE, whereas in Firefox the message is "...SetMute is not a function". Note that the call is the same as that used in the links, and the links work fine.

What's going wrong here? It seems to me that the object isn't fully constructed yet, or something like that, but I can't find a way around it. I've tried onloads on just about everything, to no avail. I've tried detecting the object's existence (if (document.movie1) etc), but even when it seems to exist, the call fails. How can I get this thing to mute before it starts?

See it in action (high-bandwidth connection is required because the movies are rather large):

My code:

8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<

<html>
<head>
<title>Simple QuickTime Movie Controls</title>
</head>

<script language ="JavaScript">
<!--

/* define function that calls QuickTime's "Play" method */
function PlayIt(anObj)
{
anObj.Play();
}

/* define function that calls QuickTime's "Stop" method */
function StopIt(anObj)
{
anObj.Stop();
}

/* function to mute movie */
function MuteMe(anObj)
{
anObj.SetMute(true);
}

//-->
</script>

<body>

<P>
This page uses JavaScript to control a QuickTime movie...
</P>

<div align=center>
<table>
<tr>
<td width=200>
<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase="width="180" height="160"
id="movie1">
<PARAM name="src" value="PICT0025.MOV">
<EMBED width="180" height="160"
src="PICT0025.MOV"
TYPE="video/quicktime"
PLUGINSPAGE="name="movie1"
enablejavascript="true">
</EMBED>
</OBJECT>

<P> Movie1 </P>

</td>
<td width=200>

<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
codebase="width="180" height="160"
id="movie2" >
<PARAM name="src" value="PICT0027.MOV">

<EMBED width="180" height="160"
src="PICT0027.MOV"
TYPE="video/quicktime"
PLUGINSPAGE="name="movie2"
enablejavascript="true">
</EMBED>
</OBJECT>

<P> Movie2 </P>
</td>
</tr>
</table>
</div>

<P>Pass movie name to JavaScript functions as a parameter: <br>
<a href="javascript:playIt(document.movie1);">PlayIt(movie1)</a><br>
<a href="javascript:StopIt(document.movie1);">StopIt(movie1)</a><br>
<a href="javascript:MuteMe(document.movie1);">MuteMe(movie1)</a><br>
<a href="javascript:playIt(document.movie2);">PlayIt(movie2)</a><br>
<a href="javascript:StopIt(document.movie2);">StopIt(movie2)</a><br>
<a href="javascript:MuteMe(document.movie2);">MuteMe(movie2)</a><br>
</P>

<P>Control movie by name directly: <br>
<a href="javascript:document.movie1.Play();">movie1.Play()</a><br>
<a href="javascript:document.movie1.Stop();">movie1.Stop()</a><br>
<a href="javascript:document.movie1.SetMute(true);">movie1.Mute(true)</a><br>
<a href="javascript:document.movie2.Play();">movie2.Play()</a><br>
<a href="javascript:document.movie2.Stop();">movie2.Stop()</a><br>
<a href="javascript:document.movie2.SetMute(true);">movie2.Mute(true)</a><br>
</P>

<P>Control movie by index in the embeds[ ] array:<br>
(Does not work for IE 6 and later if you use the Object tag)
<a href="javascript:document.embeds[0].Play();">embeds[0].Play()</a><br>
<a href="javascript:document.embeds[0].Stop();">embeds[0].Stop()</a><br>
<a href="javascript:document.embeds[1].Play();">embeds[1].Play()</a><br>
<a href="javascript:document.embeds[1].Stop();">embeds[1].Stop()</a><br>
</P>

<script language ="JavaScript">
document.movie1.SetMute(true);
</script>

</body>
</html>

8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<8<

Any help or hints would be appreciated...
 

Perhaps you would be kind enough to put two small test movies up.

Even on my 2Mb (soon to be 4Mb ;o) ADSL link, the 10.3Mb and 10.2Mb movies hang at about 40% each, so testing the page is not really workable.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 

The "Mute" links in the top two sets of links both work 100% - when the movie has finished downloading and is in the middle of playing.

Therefore, once the movie has loaded, try calling the mute function directly before the play function.

Hope this helps,
Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
That's exactly the problem. I don't know when "once the movie has loaded" is. I have tried onLoad on the object, the embed, and the page, and even when they fire, the call doesn't work.

It begins working at some point, as the user can click on the links and they always work. And of course the script could just wait for "a while" (good luck) and it would work. But by then the movies would have all started together most clangorously.

Part of the solution might be getting the movies not to start when they load, then explicitly starting them later. But when later? That's really the question.
 
Afaik, onload only works for document.body - have you tried that?

----------
Memoria mihi benigna erit qui eam perscribam
 
I am terribly sorry but I do not have QT and I am using a very old laptop with damaged HDD so I won't be downloading it :(

If you give me a new laptop, I'll take a look ;)

How about adding:

<param name="SetMute" value="true" />



----------
Memoria mihi benigna erit qui eam perscribam
 
I don't know when "once the movie has loaded" is

Check out the Apple developer docs for QT & JS:


More specifically, the "GetPluginStatus" property, which returns:

"Waiting"—waiting for the movie data stream to begin

"Loading"—data stream has begun, not able to play/display the movie yet

"Playable"—movie is playable, although not all data has been downloaded

"Complete"—all data has been downloaded

"Error: <error number>"—the movie failed with the specified error number

Note: Even though the method is named GetPluginStatus it gets the status of a specific movie, not the status of the plug-in as a whole. If more than one movie is embedded in a document, there can be a different status for each movie. For example, one movie could be playable while another is still loading.

Hope this helps,
Dan

[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]
 
True; I saw that doc and messed about with this idea a bit. It seemed to me that these calls were parallel to the SetMute call and would therefore fail in the same way if the object were in the same condition.

In other words, if instead of asking the object to mute, I asked it if it were ready to be asked to mute, it seemed I would get the same error, because the object reference was such that it wasn't ready to answer either question. But I'm not sure I fully explored this idea, so I will do that.

* watch this space *

Thanks for the ideas, I can hear that they are well researched and considered.

 

Use the onload event of the body to start a timer (using setInterval) to poll the state - within a try / catch block so no errors are thrown. When it is ready, you can mute then play. Sounds like it should work, anyway ;o)

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
KA-CHING!

We got it. The try/catch was the last idea we needed. Here is the relevant code:

<script language ="JavaScript">
<!--

function TryPlay ()
{
var erroredout = false;
try {
MuteMe(document.movie1);
PlayIt(document.movie1);
MuteMe(document.movie2);
PlayIt(document.movie2);
}
catch(e) {
erroredout = true;
}
if (erroredout) {
setTimeout("TryPlay()", 1000);
}
}

//-->
</script>

<body onLoad="TryPlay();">

Also needed:

<param name="autoplay" value="false">

(together with the above code, I'll leave it to you to pull it all together, or you can play/view the end result at:

(also, btw, didn't need the GetPluginStatus property)

Thanks everybody for your helpful suggestions, especially BillyRay for the solution. One more in the bag!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top