Java Audio and Timer Functions, Audio Breaking
Hello. Currently, I have a program which is a bit heavy. It updates 2500 JLabels every 75 ms. It's been working fine, but it seems that I can't play music. When I try to play music while the program is on its timer, the music breaks and stops playing. When the computer is not doing anything with the JLabels, the music plays indefinitely, as it should. Below is my code. I used an Applet to play the music. The code beneath is a button's listener, which toggles the music.
Does anyone have any suggestions as to how I can make the music play while the JLabels are being changed?
music = new Applet();
private class SListener implements ActionListener
public void actionPerformed(ActionEvent e)
musicPlaying = !musicPlaying;
Re: Java Audio and Timer Functions, Audio Breaking
First off, newAudioClip(...) is a static method of Applet and doesn't require constructing an instance of Applet in order to use it.
Second, there is no point stop()ping a new AudioClip that hasn't ever been started. You need to create the AudioClip just once and retain a reference to it.
Finally, you need to understand Swing's single threaded rule and how to execute non-GUI code on a Thread other than the EDT. To learn this, go through the tutorial Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
Since the issue is related to Swing, I'm moving this thread. It's not an 'Advanced' Java question either.