0

My applet creates a new sound every time an impact occurs, which is very frequently.

How come, when the sounds become too numerous, the game ceases to run smoothly?

Here is the code that gets called many, many times:

class soundThread extends Thread
{
    String sound;
    soundThread(String i_sound)
    {
        sound = i_sound;
    }
    public void run()
    {
        try{
            URL path = new URL(getClass().getProtectionDomain().getCodeSource().getLocation(), sound+".wav");
            AudioClip clip = Applet.newAudioClip(path);
                //checkpoint A
            clip.play();
                //checkpoint B
        }catch(Exception e){System.err.println("err= soundThread_error");e.printStackTrace();}
    }
}

The longest pause occurs at clip.play();. Any clue why it would take so long to play the clip? And how can I fix it?

2
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by NormR1
0

No, sorry. But upon searching for it I did not find anything helpful :/

0

It explains what the code does. It doesn't say how to change what it does.
If you want the sounds to play sequentially, you'll have to write code to call play() after the last clip has finished.

Edited by NormR1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.