Dennis
Dennis

Reputation: 3596

Java: Any Simple Way to Play Audio Files on Mac?

So I'm trying to make a game that includes many different sound effects to be played during the gameplay. However, the application keeps crashing after about a minute or so, saying:

Invalid memory access of location 0x54008 rip=0x11c7737fd

or sometimes another error related to the memory as well. In the report, it said that my program was using too much memory and was crashed due to the low memory. However, it works perfectly fine on Windows, not just on another computer but even on the same computer (I'm using macbook btw) using a virtual machine. I have updated Java to the latest version. Is there anyway to solve this problem, or is there at least another way that works fine on Mac (Lion) as well? I used the code from the following link to play audio files in my program:

http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml

Thanks in advance.

Upvotes: 0

Views: 1259

Answers (1)

Greg Kopff
Greg Kopff

Reputation: 16605

Can you use a java.applet.AudioClip returned from Applet.newAudioClip()?

The AudioClip interface is a simple abstraction for playing a sound clip. Multiple AudioClip items can be playing at the same time, and the resulting sound is mixed together to produce a composite.

(It doesn't matter that you're not making a Java Applet - you can still use these classes ...)

AudioClip clip = Applet.newAudioClip(resource);
clip.play();

(I've used this without incident on Snow Leopard.)

Upvotes: 1

Related Questions