Sign in to follow this  

Java Audio Clip() Plays Sometimes?

Recommended Posts

In my game applet I have decided to use Java Clip because all my sound clips are less than a second in length. The problem I am facing is 90% of the time the clips play when they should, the other 10% I hear no playback at all.

Source code under my main applet:

private void LoadGameSounds() throws Exception{
File soundFile;
AudioInputStream sound;
Clip clip;

for (int i = 0; i < 5; i++){
soundFile = new File("drop"+(i+1)+".wav");

sound = AudioSystem.getAudioInputStream(soundFile);
// load the sound into memory (a Clip)
clip = AudioSystem.getClip();;

board.SetSoundClip(i, clip);

The SetSoundClip() Function under MainBoard:

public void SetSoundClip(int i, Clip clip){
soundClip[i] = clip;
catch(LineUnavailableException e){}

Since the MainBoard judges whether pieces have 'dropped', MainBoard plays the audio clips.

...if piece dropped:

All sound files do load unto the soundClip array and they all playback...90% of the time :D

[Edited by - isometrixk on December 6, 2010 10:08:17 AM]

Share this post

Link to post
Share on other sites
Bump for suggestions or answers? I debugged the program and it plays the sounds everytime in the debugger. I'm confused.

Edit...I found this link, I'm going to try it out when I get home:

[Edited by - isometrixk on December 6, 2010 10:44:19 AM]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this