We help IT Professionals succeed at work.

Java/Real Audio

darryl robinson
on
Medium Priority
423 Views
Last Modified: 2013-11-18
I'm hoping someone here may have encountered (and
overcome) similar difficulties in using Java to control
an embedded RealAudio plugin.

Using the sample code provided by Prognet, I created
an applet that simply sets the source of a RealAudio plugin to a URL and then calls the plugin's DoPlayPause method.
The plugin seems to respond to the SetSource method by attempting to find the selected sound (a .rpm file). However, it never begins to play.

An excerpt from the applet source code follows:
import java.awt.*;
import java.applet.*;
import netscape.javascript.JSException;
import netscape.javascript.JSObject;
import RAObserver;
import RAPlayer;
...
        void button1_Clicked(Event event) {
          JSObject jsWin = JSObject.getWindow(this);;
          JSObject jsDoc = (JSObject)jsWin.getMember("document");
          RAPlayer ra = (RAPlayer)jsDoc.getMember("javaPlug1");;
          ra.SetAutoStart(true);    
          ra.SetSource("http://1.1.1.1/audio/bahamas.rpm");
          ra.DoPlayPause();
        }
...

Performing the task using JavaScript works without a hitch. The following code not only sets the source, but it plays the sound:
<SCRIPT LANGUAGE="JavaScript">
  function playURL() {
    document.javaPlug1.SetSource("http://1.1.1.1/audio/bahamas.rpm");
    document.javaPlug1.DoPlayPause();
  }
</SCRIPT>

However, when I call this JavaScript function from my Java applet, Navigator freezes. I've tried calling the function using both "call" and "eval", as follows:
        String args[]={""};
        jsWin.call("playURL", args);
OR
        jsWin.eval("playURL();");

I'm using Netscape Navigator 3.01 Gold with the RealPlayer 4.0 plugin. I also tried it with the RealAudio Player 3.0 plugin.

Has anyone else encountered this problem? If so, did you find a workaround? If you could post and mail your response, it would be helpful.

Darryl Robinson (darrylr@robotica-inc.com)
Comment
Watch Question

Yes, I ran into a similar problem writing a demo for one of my clients.

Since I was in a rush, I cheated (counts as a work arround, I guess).

What I did was create a page that contained a parent Frame with the RA script in it using one row. Created the frame with the FRAMBORDER set to No so as to not show what I was doing.

I then placed my applet in a child frame.

In this way I could control loading an initial page that contained no scripts. And when Java requested to play an RA script I would call:

showDocument(MyRAScriptURL, "_parent");

This call changes thepage of the parent frame to one with identical content plus the RA script.

The customer didn't buy so I didn't look much more into the problem but I did find that the source of the problem is that the RA classes are added to class libraries of scripting language and not to the browsers java CLASSLIB path which changes from browser to browser but is never the same as the JDK's.


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
JPK,

Thanks for the reply. I'm going to give your creative workaround a shot and let you know how it goes. Meanwhile, I have some additional info to lend to the discussion. Even when I place RAObserver.class and RAPlayer.class in the same directory as the applet, the problem persists. Shouldn't these classes be found if they're in the same directory as the applet (regardless of the browser's classpath)?

Regards,
Darryl R.
Not necesarily, remember that JAVAScript and JAVA are not the same language. Although Javascript is "inspired " by Java.

Thats the main reason that communicating scripts with applets within the client  is such a nightmare and usualy left to sockets.

Author

Commented:
But if I'm using Netscape Navigator, the Netscape JavaScript classes (netscape.javascript.JSException and netscape.javascript.JSObject) are built into the browser. I agree that Java/JScript communication is a nightmare (based on the number of hours that I wasted on it yesterday), but I think it may be the RA classes themselves and not the classpath issue.
Its a posibility, I'll try to look into int tommorow or saturday for intelectual pleasures sake.

My e-mail is:

 jkelleghan@usa.net

if you wish to continue this alternate thread.
Finaly had time to look into your problem more deeply

Your right, it looks like an RA implementation over Netscape issue. When attempting a solution using ActiveX (via MSIE) it worked fine.

Let me know how the workarround worked for you.

Author

Commented:
Finally got around to implementing this yesterday. The workaround works great. The only hitch I encountered after getting the sound to play on demand is that the applet is now incompatible with Internet Explorer (because it relies on Netscape's javacript classes).

Thanks again for a very creative solution to this problem.
Darryl R. (darrylr@robotica-inc.com)
You could use the System getProperties class to work arround this problem.

Use a call to:

String s = System.getProperty("java.vendor");

to determine which browser you are using.

You can then decide if you want to call the page that contains the Netscape Java script or one that contains an ActiveX component.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.