From: [EMAIL PROTECTED]
Subject: Re: Netscape Callbacks Example - playstatechange

Here's a simple example that handles OnPlayStateChange events in an applet. It
works in both Netscape 4.6 and IE 5 on Windows/NT-- have not tested other
versions or platforms.

First, the HTML file:


<HEAD>

<!--
   -- *** IE Linkage Functions (not needed for or processed by Navigator) ***
   -->
<SCRIPT LANGUAGE="VBScript">

'
' Get play-state-change events from player. Note inconsistency between this
' handler and the plug-in one. No last state information. <Sigh>
'
Sub ImageWindow_OnPlayStateChange( a )
      Monitor.OnPlayStateChange a, 0
End Sub

</SCRIPT>

</HEAD>
<BODY>
<OBJECT ID=ImageWindow
           NAME="ImageWindow"
           CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"
           WIDTH="240" HEIGHT="180">
      <PARAM NAME="CONTROLS" VALUE="ImageWindow">
      <PARAM NAME="CONSOLE" VALUE="1">
      <PARAM NAME="SRC"
           VALUE="rtsp://scallop.dragonsys.com/video/ellisonoow98.rm"><EMBED
         NAME="ImageWindow"
         TYPE="audio/x-pn-realaudio-plugin"
         CONTROLS="ImageWindow"
         CONSOLE="1"
         WIDTH="240" HEIGHT="180"></OBJECT><BR>
<OBJECT ID=ControlPanel
           NAME="ControlPanel"
           CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"
           WIDTH="240" HEIGHT="32">
      <PARAM NAME="CONTROLS" VALUE="ControlPanel">
      <PARAM NAME="CONSOLE" VALUE="1"><EMBED
         NAME="ControlPanel"
         TYPE="audio/x-pn-realaudio-plugin"
         CONTROLS="ControlPanel"
         CONSOLE="1"
         WIDTH="240" HEIGHT="32"></OBJECT><BR>
<APPLET NAME="Monitor" MAYSCRIPT
           CODE="Monitor.class"
           ARCHIVE="Monitor.jar"
           WIDTH="0" HEIGHT="0">
      <PARAM NAME="PLAYER_NAME" VALUE="ImageWindow">
      <PARAM NAME="PLAYER_SRC"
           VALUE="rtsp://scallop.dragonsys.com/video/ellisonoow98.rm">
      </APPLET>

</BODY>



Now here's the Java file. You will need to package this guy up along with the
RAPlayer.class file and the RMObserver.class file in a JAR file (here called
Monitor.jar) All we do is assume we are running under Netscape. If we fail to
obtain an RAPlayer instance in our init() method, we gracefully accept the 
error
and continue running -- assume that we are in an IE browser. Our notifications
must then come from VBScript handlers, like the OnPlayStateChange one defined
above in the HTML file.


import java.applet.Applet;

import netscape.javascript.JSObject;
import netscape.javascript.JSException;

import RMObserver;
import RAPlayer;

public class Monitor extends Applet implements RMObserver {
      private RAPlayer rap = null;
      private String rapName = null;
      private String src = null;

      public void init()
      {
           System.out.println( "*** init" );
           rapName = getParameter( "PLAYER_NAME" );
           src = getParameter( "PLAYER_SRC" );
      }

      public void start()
      {
           System.out.println( "*** start" );
           rap = null;
           try {
                JSObject win = JSObject.getWindow( this );
                System.out.println( win );
                rap = (RAPlayer )win.eval( "document.embeds['" + rapName + "']"
);

                //
                // This will fail under MS IE -- no biggy. We use VBScript 
to do
                // what we do here.
                //
                rap.AdviseG2( this );

                //
                // Direct our player to the proper location.
                //
                rap.SetSource( src );
           }
           catch ( Exception e ) {
                System.out.println( e );
                rap = null;
           }
      }

      public void stop()
      {
           System.out.println( "*** stop" );
      }

      public void destroy()
      {
           System.out.println( "*** destroy" );
      }

      //
      // Get play-state-change events from the player
      //
      public boolean OnPlayStateChange(int newPlayState, int foo ){
           System.out.println( "newPlayState: " + newPlayState + "  foo: " +
                                    foo );
           return true;
      }

      public boolean OnPosLength(int Position, int Length){
           return true;
      }

      public void onClipOpened(String shortClipname, String url){
      }

      public void onClipClosed(){
      }

      public void onShowStatus(String statustext){
      }

      public void onGoToURL(String url, String target){
      }

      public boolean OnLengthChange(long newlength){
           return true;
      }

      public boolean OnVolumeChange(int volume){
           return true;
      }

      public boolean OnTitleChange(String title){
           return true;
      }

      public boolean OnAuthorChange(String author){
           return true;
      }

      public boolean OnCopyrightChange(String copyright){
           return true;
      }

      public boolean OnClipSizeChange(long width, long height){
           return true;
      }

      public boolean OnErrorMessage(String text){
           return true;
      }

      public boolean OnStatsInfoChange(String text){
           return true;
      }

      public boolean OnPresentationOpened(){
           return true;
      }

      public boolean OnPreFetchComplete(){
           return true;
      }

      public boolean OnPresentationClosed(){
           return true;
      }

      public boolean OnStatisticsChanged(){
           return true;
      }

      public boolean OnPreSeek(int OldTime,    int NewTime){
           return true;
      }

      public boolean OnPostSeek(int OldTime, int NewTime){
           return true;
      }

      public boolean OnStop(){
           return true;
      }

      public boolean OnBuffering(int Flags, short PercentComplete){
           return true;
      }

      public boolean OnContacting(String HostName){
           return true;
      }

      public boolean OnResized(long lwidth, long lheight){
           return true;
      }

      public boolean OnLButtonDown(int nFlags, int nX, int nY){
           return true;
      }

      public boolean OnLButtonUp(int nFlags, int nX, int nY){
           return true;
      }

      public boolean OnLButtonDblClk(int nFlags, int nX, int nY){
           return true;
      }

      public boolean OnRButtonDown(int nFlags, int nX, int nY){
           return true;
      }

      public boolean OnRButtonUp(int nFlags, int nX, int nY){
           return true;
      }

      public boolean OnRButtonDblClk(int nFlags, int nX, int nY){
           return true;
      }

      public boolean OnMouseMove(int nFlags, int nX, int nY){
           return true;
      }

      public boolean OnKeyDown(int nFlags, int nKey){
           return true;
      }

      public boolean OnKeyUp(int nFlags, int nKey){
           return true;
      }

      public boolean OnKeyPress(int nFlags, int nKey){
           return true;
      }
      public boolean OnClipOpen(){
           return true;
      }
      public boolean OnKeyDown(int keycode){
           return true;
      }
      public boolean OnKeyUp(int keycode){
           return true;
      }
      public boolean OnKeyPress(int keycode){
           return true;
      }
      public boolean OnVolume(int newvolume){
           return true;
      }
      public boolean OnMuteChange(boolean muted){
           return true;
      }

} // end Monitor class



Hope this helps.


Brad


*******************************************************
The RealForum is an email discussion group focused on using RealNetworks
products. The RealForum is a place to post messages about the best methods
for creating content using RealNetworks technologies and the planning and
implementation of streaming-media web sites.  Archives of RealForum can
be found at http://realforum.real.com

If you ever want to remove yourself from this mailing list,
you can send mail to <[EMAIL PROTECTED]> with the following
command in the body of your email message:

    unsubscribe realforum

or from another account, besides the address you subscribed with:

    unsubscribe realforum <[EMAIL PROTECTED]>

Reply via email to