I have a function that is called every time the user clicks which will start the music if the screen has changed. The only problem with it right now is that it does not stop. I have figured out that this is because clip = AudioSystem.getClip(); won't return the currently playing clip, it returns a random location every time. How do I make sure that clip gets the value of the currently playing clip so that I can stop it?
The "StartBGMusic" function
public void startBGMusic() throws LineUnavailableException, IOException
{
clip = AudioSystem.getClip();
System.out.println(clip);
try
{
if(SCREEN_CHECK != Screen)
{
clip.stop();
clip.close();
if(Screen != 14 && Screen != 19 && Screen != 16 && Screen != 15 && Screen != 17)
{
clip.open(AudioSystem.getAudioInputStream(getClass().getResource("UpbeatFunk.wav")));
clip.loop(99999);
}
else
{
clip.open(AudioSystem.getAudioInputStream(getClass().getResource("Background Music.mid")));
clip.loop(99999);
}
}
SCREEN_CHECK = Screen;
}catch (Exception e)
{
e.printStackTrace(System.out);
}
}