title: Stopping looping sound in java
body: <p>So I have a class to play sound and I have a option to loop it or play it once and a stop option but the stop option does not stop the looping here is the code to stop the sound:
  EDIT added the whole thing
      package me.welsar55.story;</p>
  
  <pre><code>import java.io.File;
  
  import javax.sound.sampled.AudioInputStream;
  import javax.sound.sampled.AudioSystem;
  import javax.sound.sampled.Clip;
  
  public class Sound {
  
  public static synchronized void clip(final String fileName, final String action) 
  {
      new Thread(new Runnable()
      { 
          public void run() 
          {
  
              if(action.equalsIgnoreCase("play"))
              {
                  try 
                  {
                      Clip clip = AudioSystem.getClip();
                      AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(fileName));
                      clip.open(inputStream);
                      clip.start();
                  } 
                  catch (Exception e)
                  {
                      System.out.println("play sound error: " + e.getMessage() + " for " + fileName);
                  }
              }
              else if(action.equalsIgnoreCase("loop"))
              {
                  try 
                  {
                      Clip clip = AudioSystem.getClip();
                      AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(fileName));
                      clip.open(inputStream);
                      clip.loop(Clip.LOOP_CONTINUOUSLY);
                  } 
                  catch (Exception e)
                  {
                      System.out.println("play sound error: " + e.getMessage() + " for " + fileName);
                  }
              }
   else if(action.equalsIgnoreCase("stop"))
  {
      try 
      {
          Clip clip = AudioSystem.getClip();
          AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(fileName));
          clip.open(inputStream);
          clip.stop();
      } 
      catch (Exception e)
      {
          System.out.println("play sound error: " + e.getMessage() + " for " + fileName);
      }
  }
          }
      }).start();
  }
  </code></pre>
  
  <p>}</p>