Add SoundWrapper class

master
John 2022-06-19 13:54:38 -04:00
parent 3359ab9ff1
commit 7a63db1349
1 changed files with 29 additions and 0 deletions

29
src/SoundWrapper.java Normal file
View File

@ -0,0 +1,29 @@
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import java.io.*;
public class SoundWrapper implements Serializable {
transient public Sound sound;
public String soundString;
// please note that not as many constructors were implemented as BufferedImage, as this class was created before most sounds were added;
// as such, backwards compatibility was not needed
public SoundWrapper(String soundLocation) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
sound = new Sound(soundLocation);
soundString = soundLocation;
}
public SoundWrapper() {}
@Serial
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(soundString);
}
@Serial
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException, UnsupportedAudioFileException, LineUnavailableException {
Object o;
o = in.readObject();
sound = new Sound((String)o);
}
}