Inside Macintosh: QuickTime Reference

| Previous | Chapter Contents | Chapter Top | Next |

Sample JavaScript Usage

The following is a simple HTML file that shows four equivalent ways to specify the movie object. In Listing 6, a JavaScript function takes a QuickTime movie and calls its Play() and Stop() methods.

Note:
The sample code below works only with browsers that support communication between JavaScript and the QuickTime plug-in or ActiveX control. If you embed your movie in a page using the Object tag, Internet Explorer 6 and later do not populate the embeds[] array. Use an alternate method of addressing movies if you embed movies using the Object tag.

Listing 6  Using JavaScript functions to play and stop a QuickTime movie

<html>
<head>
        <title>Very Simple QuickTime Movie Test</title>
</head>

<script language ="JavaScript">

<!--
        /* a javascript function that takes a QT movie and calls its "Play" method */
        function PlayIt(anObj)
        {
                anObj.Play();
        }
        /* a javascript function that takes a QT movie and calls its "Stop" method */
        function StopIt(anObj)
        {
                anObj.Stop();
        }
//-->

</script>
    <body bgcolor="#ffffff">

                <br>
                This is a test of QuickTime embedded...<br>
                <br>

     <table>
          <tr>
          <td width=200>
              <OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
                      codebase="http://www.apple.com/qtactivex/qtplugin.cab"
                      width="180" height="160"
                      id="movie1" >

               <PARAM name="src" value="My.mov">

               <EMBED width="180" height="160"
                      src="My.mov"
                      name="movie1"
                      enablejavascript="true">
               </EMBED>
              </OBJECT>
          </td>

          <td width=200>
              <OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
                      codebase="http://www.apple.com/qtactivex/qtplugin.cab"
                      width="180" height="160"
                      id="movie2" >

               <PARAM name="src" value="MyOther.mov">

               <EMBED width="180" height="160"
                      src="MyOther.mov"
                      name="movie2"
                      enablejavascript="true">
               </EMBED>
              </OBJECT>
          </td>
          </tr>
     </table>

<br><br>Calling a JavaScript function which takes an object referenced by name<br>
<a href="javascript:PlayIt(document.movie1);">javascript:PlayIt(document.movie1)</a><br>
<a href="javascript:StopIt(document.movie1);">javascript:StopIt(document.movie1)</a><br>
<a href="javascript:PlayIt(document.movie2);">javascript:PlayIt(document.movie2)</a><br>
<a href="javascript:StopIt(document.movie2);">javascript:StopIt(document.movie2)</a><br>

<br>Calling an object (referenced by name) method directly<br>
<a href="javascript:document.movie1.Play();">javascript:document.movie1.Play()</a><br>
<a href="javascript:document.movie1.Stop();">javascript:document.movie1.Stop()</a><br>
<a href="javascript:document.movie2.Play();">javascript:document.movie2.Play()</a><br>
<a href="javascript:document.movie2.Stop();">javascript:document.movie2.Stop()</a><br>

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

<br>
Calling an object (indexed in the document "embeds" array by name) method directly<br>
(Does not work for IE 6 and later if you use the Object tag)
<a href="javascript:document.embeds['movie1'].Play();">javascript:document.embeds['movie1 ].Play()</a><br>
<a href="javascript:document.embeds['movie1'].Stop();">javascript:document.embeds['movie1'].Stop()</a><br>
<a href="javascript:document.embeds['movie2'].Play();">javascript:document.embeds['movie2'].Play()</a><br>
<a href="javascript:document.embeds['movie2'].Stop();">javascript:document.embeds['movie2'].Stop()</a><br>

        </body>
</html>


© 2000 Apple Computer, Inc.

Inside Macintosh: QuickTime Reference

| Previous | Chapter Contents | Chapter Top | Next |