internet.com

Developer Channel

SYMM

JavaScript Control of RealPlayer (2)

RealPlayer Methods
In JavaScript, methods allow you to do something to or with your objects. RealPlayer supports a variety of methods that can be called upon to do work in your JavaScript. Among numerous other options, these methods allow you to start and stop the player, select a point within a clip to play, and recover performance statistics.

For my example today, I want to focus on two methods for controlling player playback:

DoPlay() will start the clip playing in the RealPlayer. DoStop() will stop the clip playing in the RealPlayer. With these two methods, I have enough to make the player start and stop my presentation.

Capturing Events
In order to call my DoPlay() or DoStop() methods, I need to have some kind of event happen. Obviously, clicking on buttons or an image map might do the trick. So for this example, I add the following images to my HTML:

PLAY Button STOP Button

or, in HTML as:

<IMG SRC="play.gif" WIDTH="75" HEIGHT="75" BORDER="0" ALT="PLAY BUTTON">
<IMG SRC="stop.gif" WIDTH="75" HEIGHT="75" BORDER="0" ALT="STOP BUTTON">

Now that I have buttons to click, I need to make make them active. I do this by adding an anchor to each:

<A HREF="javascript:void(0)" onClick="document.libertyclip.DoPlay()"><IMG SRC="play.gif" WIDTH="75" HEIGHT="75" BORDER="0" ALT="PLAY BUTTON"></A>
<A HREF="javascript:void(0)" onClick="document.libertyclip.DoStop()">
<IMG SRC="stop.gif" WIDTH="75" HEIGHT="75" BORDER="0" ALT="STOP BUTTON"></A>

If you are new to JavaScript, the code here might look a little intimidating. It is really not that hard. The "javascript:void(0)" value to the HREF attribute simply tells the browser to ignore that actual HREF value. I do not want to send our visitor to another Web page. I simply want to make use of the linking power of the browser to launch or stop my video clip when the visitor clicks the graphic. I do just that with the OnClick event. The instructions "document.libertyclip.DoPlay()" is the RealPlayer method being told to do its thing within the Web page document on the EMBED source named "libertyclip.". Now that we have the pieces in place, it is time to test it all out.


<< Prev 1 • 2 • 3 Next >>
 
The Latest WebDev Tips from DevX

Receive news via our XML/RSS feed
XMLRSS



Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers