JavaSonics

SDK

Documentation


Web Home

SDK Home

Docs

Test PHP

Test ASP

Test ASP.NET

Examples

Demos

Download

Purchase

Support

Forum

Login

Contact Us

Company


JavaSonics ListenUp is no longer for sale.

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.

Click Here for an Example

Setting up the <applet> Tag

To 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 JavaScript

To 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:

document.JavaSonicRecorderUploader.play();

See the complete list of the applet methods that can be called from JavaScript.

Callbacks from Java to JavaScript

To enable JavaScript to receive notification when the Recorder Applet starts, plays, records, etc, set the Applet's "requestStateChanges" parameter to "yes".

<param name="requestStateChanges" value="yes">  

ListenUp will then call a JavaScript function called "LUPJS_StateChanged( previousState, newState )" whenever the state changes. You define that function in JavaScript. This JavaScript function can enable or disable HTML buttons, etc depending on the state of the applet. For example, it can check if the player has stopped then you could disable your "Stop" button. For example:

function LUPJS_StateChanged( previousState, newState )
{
if( newState == "stopped" ) doument.listenupControlForm.stopButton.disabled = true;
else document.listenupControlForm.stopButton.disabled = false;
}

Knowing if the Applet is Ready

You 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() )

[Top]  [Previous] [Next]
 


© 2001-2006 Mobileer, Inc.   This page is from the ListenUp SDK. You can download the SDK from here.