Skip to content

Commit c6d70ca

Browse files
committed
Use URL overload for Sound
1 parent bb963b4 commit c6d70ca

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

src/main/java/org/teachingextensions/logo/Sound.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.teachingextensions.logo;
22

33
import java.awt.Toolkit;
4-
import java.io.File;
54
import java.net.URL;
65

76
import 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
/**
3433
* Sets a sound that you can play through your speakers.
3534
* Use a TKPSound (there is a list)<br>
@@ -44,8 +43,7 @@ public synchronized void setSound(TKPSound mySound)
4443
resource = this.getClass().getClassLoader().getResource(sound);
4544
}
4645
if (resource == null) { throw new IllegalStateException("Could not get TKPSound: " + sound); }
47-
this.soundFilename = resource.toString();
48-
this.soundFilename = this.soundFilename.replace("file:", "");
46+
this.soundUrl = resource;
4947
}
5048
/**
5149
* Plays a TKPSound through your speakers.
@@ -54,7 +52,7 @@ public synchronized void setSound(TKPSound mySound)
5452
*/
5553
public synchronized void playSound()
5654
{
57-
final String sound = this.soundFilename;
55+
final URL sound = this.soundUrl;
5856
new Thread(new Runnable()
5957
{
6058
@Override
@@ -63,7 +61,7 @@ public void run()
6361
try
6462
{
6563
Clip clip = AudioSystem.getClip();
66-
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new File(sound));
64+
AudioInputStream inputStream = AudioSystem.getAudioInputStream(sound);
6765
clip.open(inputStream);
6866
clip.start();
6967
}

0 commit comments

Comments
 (0)