Results 1 to 2 of 2
  1. #1
    mjkaufer is offline Member
    Join Date
    May 2013
    Rep Power

    Default 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?

    Java Code:
    	music = new Applet();
    Java Code:
           private class SListener implements ActionListener
              public void actionPerformed(ActionEvent e)
    				musicPlaying = !musicPlaying;

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default 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.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Java and audio output
    By Humphrey Bogart in forum New To Java
    Replies: 3
    Last Post: 03-20-2012, 06:21 PM
  2. pause audio in java
    By Saran185 in forum Advanced Java
    Replies: 1
    Last Post: 03-09-2011, 03:04 PM
  3. Audio processing in Java?
    By blind melon in forum New To Java
    Replies: 11
    Last Post: 12-03-2010, 12:22 AM
  4. Streaming Audio in Java Application?
    By jfxdd in forum Advanced Java
    Replies: 2
    Last Post: 11-24-2009, 08:13 PM
  5. Problems with Java Audio Recording
    By in forum Advanced Java
    Replies: 2
    Last Post: 03-27-2009, 11:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts