title: Java audio crackling
body: <p>When I am playing the audio on my Java desktop application, the sound begins to crackle and fuzz out. I don't know why, any suggestions? I am working on a Pokemon fan game.</p>
  <pre><code>static AudioInputStream audio = null;
  public static boolean change = false;
  static Clip clip = null;
  
  public static void music() {
      try {
          change = false;
           
          if(!Main.choosegame) {
              if(!Main.startup) {
                  if(Movement.POKEMONBATTLE) {
                      audio = AudioSystem.getAudioInputStream(new File(&quot;Res/music/pokemon battle.wav&quot;));
                  } else {
                      audio = AudioSystem.getAudioInputStream(new File(&quot;Res/music/route.wav&quot;));
                  }
              } else {
                  audio = AudioSystem.getAudioInputStream(new File(&quot;Res/music/Oak's Speech.wav&quot;));
              }
          } else {
              audio = AudioSystem.getAudioInputStream(new File(&quot;Res/music/Title Screen.wav&quot;));
          }
          clip = AudioSystem.getClip();   
          clip.open(audio);
          clip.start();
          try {
              Thread.sleep(100);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          while(clip.isActive() &amp;&amp; Main.Running &amp;&amp; !change){
              
          }
          clip.stop();
          
          audio.close();
          Thread.sleep(100);
      } catch(UnsupportedAudioFileException uae) {
          System.out.println(uae);
      } catch(IOException ioe) {
          System.out.println(ioe);
      } catch(LineUnavailableException lua) {
          System.out.println(lua);
      } catch (InterruptedException e) {
          e.printStackTrace();
      } catch(OutOfMemoryError e12) {
          clip.stop();
          change = true;
          try {
              audio.close();
          } catch (IOException e1) {
              e1.printStackTrace();
          }
          System.out.println(&quot;OUT OF MEMORY IN MUSIC&quot;);
          try {
              Thread.sleep(10);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  }
  @Override                                                                                                    
  public void run() {
      while(Main.Running) {
          music();
          try {
              Thread.sleep(100);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>