Preferably a .xm or .ogg file
You use the javax.sound packages. Look in the JavaDocs. My GAGESound library may also be of help to you. As for playing OGG, go look at JOrbis. I highly recommend using the Vorbis SPI so that you can use the JavaSound libs instead of the direct Jorbis libs.
You mean it’s possible to use the javax.sound packages to play a sound without using an applet? I’d sure like to see a simple example. By the way, I can’t load your GAGESound library.
[quote]You mean it’s possible to use the javax.sound packages to play a sound without using an applet? I’d sure like to see a simple example.
[/quote]
The javax.sound package doesn’t work in 1.1 applets, only 1.4. Applets originally used Applet.getAudioClip() until javax.sound was added to give applications and applets more sound control.
[quote]By the way, I can’t load your GAGESound library.
[/quote]
Did you put sound.jar in your classpath? You may want to try getting the “LatencyTest” example working before you try doing anything else. If you still have problems, post the error message here and I’ll take a look at it.
[quote]The javax.sound package doesn’t work in 1.1 applets, only 1.4. Applets originally used Applet.getAudioClip() until javax.sound was added to give applications and applets more sound control.
[/quote]
I don’t think I’ve been clear enough. I do not know how to play a sound without using an APPLET.
Meaning using a Frame or a JFrame.
Is that possible?
Because I run into this problem:
import java.applet.*;
import java.awt.*;
import javax.swing.*;
public class SoundFrame extends JFrame{
private AudioClip snd;
private JButton play = new JButton("Play");
private JButton stop = new JButton("Stop");
public SoundFrame(){
JPanel buttons = new JPanel();
buttons.add(play);
buttons.add(stop);
}
public boolean action(Event e, Object o){
if (e.target == play)
snd.play();
else if (e.target == stop)
snd.stop();
return true;
}
public void loadSound(){
try{
snd = getAudioClip(, "music.au"); // right here, it's in a directory not in a URL
}
catch(Exception e){
System.err.println("Error loading sound");
}
}
}
[quote]Did you put sound.jar in your classpath? You may want to try getting the “LatencyTest” example working before you try doing anything else. If you still have problems, post the error message here and I’ll take a look at it.
[/quote]
Whoops, that’s not what I meant. I meant that I can’t get even to your website. Page not found.
[quote]I don’t think I’ve been clear enough. I do not know how to play a sound without using an APPLET
[/quote]
Reread what I said. I said that javax.sound provides sound control for applications and Applets alike. i.e. It doesn’t care what you use. The only API that was applet specific was Applet.getAudioClip().
[quote]Whoops, that’s not what I meant. I meant that I can’t get even to your website. Page not found.
[/quote]
I just looked at the address. I really managed to mangle that, didn’t I? Here’s the correct address:
okay, I’ve tried running your LatencyTest from your soundAPI but I get this error.
Exception in thread “main” java.lang.NoClassDefFoundError: com/dnsalias/java/gag
e/sound/WaveEngine
at LatencyTest.main(LatencyTest.java:28 )
I tried setting the Classpath, but without succes.
By the way, I’ve figured out how to play .au files but the sound API doesn’t support .xm files, which I want to use as background music.
Convert the soudn files to a format that is supported with some other program. .AU fisn’t the greatest format either. I would just use a standard .WAV unless you require compression… then it seems that the Ogg Vorbis format is the way to go (I haven’t used it yet)… check other threads here for more info.
Your error is telling you that your classpath is wrong. Assuming that you are in the same directory as LatencyTest:
java -cp .;…\sound.jar LatencyTest
If you’re on Unix, change the semi-colon to a colon and the backslash to a forward slash.