Skip to content

Commit f0b2d96

Browse files
committed
Merge pull request #79 from jamesrcounts/master
Use URLs for sound files and include sounds in JAR
2 parents bb963b4 + 4107fd1 commit f0b2d96

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ TeachingKidsProgramming.Source.Java.iml
1717
.class.virtual_proctor.txt
1818

1919
.virtual_proctor.txt
20+
*_BACKUP_*
21+
*_LOCAL_*

build.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
<target name="stagesrc" description="Copy source files to temp build directory.">
4343
<mkdir dir="${build}/src" />
44+
<mkdir dir="${build}/soundFiles"/>
4445
<copy todir="${build}/src">
4546
<fileset dir="${src}" includes="${targetJavaClass}/*.java">
4647
<exclude name="**/tests/**" if="excludeTests" />
@@ -49,9 +50,11 @@
4950
<copy todir="${build}">
5051
<fileset dir="${rsrc}" includes="*.png" />
5152
<fileset dir="${rsrc}" includes="*.rtf" />
52-
<!--need to fix to add .wav files at /soundFiles <fileset dir="${rsrc}" includes="*.wav" />-->
5353
<!--need to fix to add .png files at /icons /> -->
5454
</copy>
55+
<copy toDir="${build}/soundFiles">
56+
<fileset dir="${rsrc}/soundFiles" includes="*.wav" />
57+
</copy>
5558
<copy todir="${build}/src/org/teachingextensions/logo">
5659
<fileset dir="${rsrc}" includes="*.png" />
5760
</copy>

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)