SDK |
Documentation |
Controlling the ListenUp Applet with JavaScript.Some browsers, notably Internet Explorer and Netscape on Windows, allow JavaScript in a web page to communicate with a Java Applet.One could, for example, hide the applet transport controls (the play, stop, and record buttons), and substitute simple JavaScript/HTML buttons instead.
Setting up the <applet> TagTo enable a Java applet to communicate with JavaScript, you must include the the following in the applet tag:mayscript="true" You must give the Applet a name in the Applet tag which can be used by JavaScript to refer to the Applet. For example: name="JavaSonicRecorderUploader"You can hide the applet's transport controls by passing it the tag: <param name="showTransport" value="no" Calling the Applet from JavaScriptTo send a command to the applet from JavaScript, use the NAME given with the Applet tag. Call document.appletName.methodName(). For example, to start playback:See the complete list of the applet methods that can be called from JavaScript.document.JavaSonicRecorderUploader.play(); Callbacks from Java to JavaScriptTo enable JavaScript to receive notification when the Recorder Applet starts, plays, records, etc, use the Applet's setRecorderStateChangedScript() method. Here we define a JavaScript function called "recorderStateChanged()". We can pass any JavaScript line. pass the name of this function to the applet with:document.JavaSonicRecorderUploader.setRecorderStateChangedScript( "recorderStateChanged();" ); Now, whenever the Applet's state changes, it will call back to recorderStateChanged() function. This JavaScript function can then query the state of the applet and redraw its buttons, etc depending on the various state variables associated with the applet. For example, it can check if the player has stopped by calling: var stopped = document.JavaSonicRecorderUploader.isStopped(); Knowing if the Applet is ReadyYou should tell the Applet to notify JavaScript when the Applet is ready to be called. This can prevent JavaScript from calling the Applet before it is loaded and ready. For example, we could have the Applet call a JavaScript function called "appletIsReady()" that enabled the HTML buttons. <param name="readyScript" value="appletIsReady();"> You can also call the isActive() method to check for Applet readyness. if( document.JavaSonicRecorderUploader.isActive() ) |