Commit dfdc3b8f authored by Valérie Maquil's avatar Valérie Maquil
Browse files

sounds can be loaded as base64

parent 29066317
......@@ -75,6 +75,8 @@ public class Scene extends Content {
/** The sound to play when painting. */
private Clip audioClip;
private boolean triggered = false;
private AudioInputStream audioIn;
private AudioInputStream audioStream;
/**
* Constructor initializing all fields.
......@@ -123,9 +125,9 @@ public class Scene extends Content {
try {
final Element imageBase64Node = element.getChild(Externalization.IMAGE_BASE64_ELEMENT);
if ((null != imageBase64Node) && (imageBase64Node.getText() != "")) {
final String[] tokens = (imageBase64Node.getText()).split(",");
System.out.println(tokens[1]);
if ((null != imageBase64Node) && (imageBase64Node.getText() != "")) { //$NON-NLS-1$
final String[] tokens = (imageBase64Node.getText()).split(","); //$NON-NLS-1$
// System.out.println(tokens[1]);
byte[] imageByte;
imageByte = Base64.getDecoder().decode(tokens[1]);
final ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
......@@ -138,9 +140,9 @@ public class Scene extends Content {
try {
final Element soundNode = element.getChild(Externalization.SOUND_NODE);
if ((null != soundNode) && (soundNode.getText() != "")) {
if ((null != soundNode) && (soundNode.getText() != "")) { //$NON-NLS-1$
final File audioFile = new File(soundNode.getText());
final AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
audioStream = AudioSystem.getAudioInputStream(audioFile);
final AudioFormat format = audioStream.getFormat();
final DataLine.Info info = new DataLine.Info(Clip.class, format);
audioClip = (Clip) AudioSystem.getLine(info);
......@@ -149,7 +151,7 @@ public class Scene extends Content {
}
catch (final FileNotFoundException e) {
throw new BuildException("The file could not be found!", e); //$NON-NLS-1$
// throw new BuildException("The file could not be found!", e); //$NON-NLS-1$
} catch (final IOException e) {
throw new BuildException("The sound could not be read!", e); //$NON-NLS-1$
} catch (final UnsupportedAudioFileException e) {
......@@ -159,7 +161,25 @@ public class Scene extends Content {
e.printStackTrace();
}
try {
final Element soundBase64Node = element.getChild(Externalization.SOUND_BASE64_NODE);
if ((null != soundBase64Node) && (soundBase64Node.getText() != "")) { //$NON-NLS-1$
final String[] tokens = (soundBase64Node.getText()).split(","); //$NON-NLS-1$
// System.out.println(tokens[1]);
final byte[] soundByte = Base64.getDecoder().decode(tokens[1]);
audioIn = AudioSystem.getAudioInputStream(new ByteArrayInputStream(soundByte));
audioClip = AudioSystem.getClip();
audioClip.open(audioIn);
}
} catch (final UnsupportedAudioFileException e) {
throw new BuildException("The sound format is not supported!", e); //$NON-NLS-1$
} catch (final IOException e) {
throw new BuildException("The sound could not be read!", e); //$NON-NLS-1$
} catch (final LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment