title: Music in Java (start/stop)
body: <p>Ok, so I am making a game and the music changes when you are in different regions or if there is an interruption, like with an AI.</p>
  
  <p>So I have JUST learned how to make music showup in my program, and now I am trying to make it stop, but I am unsure how to, below is a snippet of code where the music plays and then I try to overwite it with new music when an action occurs.</p>
  
  <pre><code>public static void songs(String word) {
          String temp = word;
          if (temp.equals("start")) {
  
              try {
  
                  try {
                      blah = new FileInputStream("C:/Users/Austin/Desktop/Storage/programimages/game/battle.wav");
  
                  } catch (Throwable e) {
                      e.printStackTrace();
                  }
                  AudioStream as = new AudioStream(blah);
  
                  AudioPlayer.player.start(as);
                  System.out.println("going");
  
              } catch (IOException e) {
                  System.err.println(e);
              }
          }
  
          if (temp.equals("stop")) {
  
              try {
  
                  try {
                      blah = new FileInputStream("C:/Users/Austin/Desktop/Storage/programimages/game/silence.wav");
  
                  } catch (Throwable e) {
                      e.printStackTrace();
                  }
                  AudioStream as = new AudioStream(blah);
  
                  AudioPlayer.player.stop(as);
                  System.out.println("stopping");
  
              } catch (IOException e) {
                  System.err.println(e);
              }
          }
      }
  </code></pre>
  
  <p>This is the only method I have been able to find that has the music play, but if you guys have any other suggestions please let me know.</p>
  
  <p>Again, I want to have sound affects and music going, and right now all that happens is one song will play, and it will not stop under any circumstance until it hits the very end of its length. I want to be able to stop songs whenever a new one should come on, and also allow sound affects to pop up.</p>
  
  <p>Thanks!
  (since I am stuck on this and need an answer now I will probably repost on one or two more java sites so I can get a response ASAP, thank you though!!!!)</p>
  
  <p>EDITED CODE: (still does not stop the current stream, any more suggestions appreciated)</p>
  
  <pre><code>public static void songs(String word) throws IOException {
      String temp = word;
  
  
      if (temp.equals("go")) {
          try {
              blah = new FileInputStream("C:/Users/Austin/Desktop/Storage/programimages/game/battle.wav");
          } catch (Throwable e) {
              e.printStackTrace();
          }
  
          AudioStream as = new AudioStream(blah);
          AudioPlayer.player.start(as);
          System.out.println("going");
      }
  
      if (temp.equals("stop")) {
  
          //don't try and do things with a null object!
          if (as != null) {
              AudioPlayer.player.stop(as);
              System.out.println("stopping1");
          }
          System.out.println("stopping2");
          AudioPlayer.player.stop(as);
      }
  }
  </code></pre>