Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Q: Audio in a JAVA Application

0 views
Skip to first unread message

Paul Sherman

unread,
Nov 5, 1996, 3:00:00 AM11/5/96
to

'Scuze me if this is an obvious one, but I am pretty new at
this...

I wanted to play() or loop() some audio from an application,
but since the audio stuff is attached to java.applet, I keep
coming back with a runtime error of:

java.lang.NullPointerException
at java.applet.Applet.getAppletContext(Applet.java:83)
at java.applet.Applet.getAudioClip(Applet.java:143)
at java.applet.Applet.getAudioClip(Applet.java:152)
at SoundApplet.load(SoundApplet.java:34)
<SNIP>

I think that this is because there is no context because of the
way that this gets called.

Just for info, here is most of the SoundApplet class:
import java.awt.*;
import java.applet.*;
import java.net.*;

public class SoundApplet extends Applet
{
URL localURL;
String localName;
AudioClip clip;

public SoundApplet(String soundName)
{
super.init();
localName = soundName;
this.load();
}

public void load()
{
try
{
localURL = new URL("file://.");
}
catch (java.net.MalformedURLException e)
{
// took out the stuff here to save space
System.exit(0);
}
// this does not work as there is no context
line 34: clip = getAudioClip(localURL,localName);
}

And here is how it gets called:
s_applet = new SoundApplet("FUTURE.aif");

I realize that there may be some seriously ugly hacks and
stylistic violations here (and if anyone wishes to point them
out, I would like to hear about it), but my questions are:
1) Why doesn't this work?
2) How could I make this work?
3) What would be the right way to do it?

So, if anyone has any suggestions for this poor newbie, I would
love to hear them. Thanks in advance.

Paul Sherman
pa...@ht.com

0 new messages