previous next

Chapter 1: Using JavaScript and the Netscape Plug-In

You can use JavaScript with the RealPlayer G2 Netscape plug-in with the following browsers:

Naming a Plug-in Instance

To refer to an embedded instance with JavaScript, you include a NAME parameter in the <EMBED> tag:


<EMBED NAME=vid SRC="..." WIDTH=300 HEIGHT=134>

You can then refer to the instance through a JavaScript command such as this:


<Input Type="button" Value="play" onClick="document.vid.DoPlay()">

Using RealPlayer Methods through JavaScript

To extend RealPlayer's Netscape plug-in functionality with JavaScript, you first embed the source file in an HTML page with the <EMBED> tag:


<EMBED NAME=javademo
SRC="demo.rpm"
WIDTH=220 HEIGHT=180
CONSOLE=one
CONTROLS=ImageWindow
BACKGROUNDCOLOR=white
CENTER=true
>

In the <EMBED> tag, the NAME parameter provides the name used by the JavaScript functions. For JavaScript to function with RealPlayer, the <EMBED> tag must not contain the parameter NOJAVA=true. That parameter prevents the browser's Java Virtual Machine from starting up.

You can then use JavaScript to issue RealPlayer commands to control the embedded presentation. The following example shows a simple form that provides a Play, Pause, and Stop button for the embedded presentation. Click here to see this presentation.


<FORM>
<INPUT TYPE="button" VALUE="Play" onClick="document.javademo.DoPlay()">
<INPUT TYPE="button" VALUE="Pause" onClick="document.javademo.DoPause()">
<INPUT TYPE="button" VALUE="Stop" onClick="document.javademo.DoStop()">
</FORM>

Additional Information
The section "Methods" lists the RealPlayer methods.

Handling URLs through <EMBED>

You can use the AUTOGOTOURL parameter in the <EMBED> tag to determine how URLs in the presentation are handled. The default value of true applies if you leave the parameter out. In this case any URL embedded in the presentation goes to the browser. If you set this parameter to false, RealPlayer sends the URL to the Java applet or application with the OnGotoURL() call.

Note
The SetAutoGoToURL() method can override the AUTOGOTOURL parameter. AUTOGOTOURL is not compatible with the RealPlayer 5.0 Netscape plug-in, however, so use SetAutoGoToURL() when planning backwards- compatibility.

Using PREFETCH with <EMBED>

The PREFETCH parameter causes RealPlayer G2 to get the stream description information before the stream starts. You can use this to find out the size and width of an embedded clip, for example, then dynamically create the <EMBED> tag for the image window, using the clip's native size for the WIDTH and HEIGHT parameters. To do this, you would embed a control, such as the default control panel, and set PREFETCH to true:


<EMBED NAME=console
SRC="demo.rpm"
WIDTH=400 HEIGHT=100
CONSOLE=one
CONTROLS=All
PREFETCH=true
>

The control fetches the stream information, then responds with the callback OnPreFetchComplete(). You next use GetClipWidth() and GetClipHeight() to determine the native size of the image window. Through a means such as DHTML, you can then create the image window control. If the width and height were 320 by 240, respectively, you could generate an <EMBED> tag like the following:


<EMBED NAME=image
SRC="demo.rpm"
WIDTH=320 HEIGHT=240
CONSOLE=one
CONTROLS=ImageWindow
>

Receiving Callbacks

When using JavaScript and the Netscape plug-in, you use LiveConnect to receive callbacks. LiveConnect is described at http://home.netscape.com/navigator/v3.0/liveconnect.html. The java directory of this manual contains callback.java, which is a sample Java class used to create a Java callback object. You can modify this class as necessary to get notifications from RealPlayer's RMObserver or RAObserver interface, both of which are included in the rpcl3260.zip file installed in the RealPlayer folder:


Copyright © 1998 RealNetworks
For information on RealNetworks' technical support, click here.
Comments on this document? Click here.
This file last updated on 12/18/98 at 17:51:29.
previous next