11package org .teachingextensions .logo ;
22
33import java .awt .Toolkit ;
4- import java .io .File ;
54import java .net .URL ;
65
76import javax .sound .sampled .AudioInputStream ;
@@ -29,7 +28,7 @@ public enum TKPSound {
2928 Ahem , Applause , BrainIsGone , CatMeow , Cheering , Crickets , DoctorMccoy , Fanfare , FargoYah , Gong , LLCoolJYaKnow ,
3029 LosingPower , Malfunction , Pizza , RunAway , SheerIgnorance , SoBeIt , StrangePerson , Stubborn , Yahoo , Yay
3130 }
32- private String soundFilename = null ;
31+ private URL soundUrl = null ;
3332 public synchronized void setSound (TKPSound mySound )
3433 {
3534 String sound = "soundFiles/" + mySound + ".wav" ;
@@ -39,16 +38,15 @@ public synchronized void setSound(TKPSound mySound)
3938 resource = this .getClass ().getClassLoader ().getResource (sound );
4039 }
4140 if (resource == null ) { throw new IllegalStateException ("Could not get TKPSound: " + sound ); }
42- this .soundFilename = resource .toString ();
43- this .soundFilename = this .soundFilename .replace ("file:" , "" );
41+ this .soundUrl = resource ;
4442 }
4543 /**
4644 * Plays a sound through your speakers. Use a '.wav' file<br>
4745 * <b>Example:</b> {@code Sound.playSound("mySound.wav")}
4846 */
4947 public synchronized void playSound ()
5048 {
51- final String sound = this .soundFilename ;
49+ final URL sound = this .soundUrl ;
5250 new Thread (new Runnable ()
5351 {
5452 @ Override
@@ -57,7 +55,7 @@ public void run()
5755 try
5856 {
5957 Clip clip = AudioSystem .getClip ();
60- AudioInputStream inputStream = AudioSystem .getAudioInputStream (new File ( sound ) );
58+ AudioInputStream inputStream = AudioSystem .getAudioInputStream (sound );
6159 clip .open (inputStream );
6260 clip .start ();
6361 }
0 commit comments