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

sound support

parent 18407283
Pipeline #601 skipped
......@@ -2,14 +2,8 @@
<scenario>
<scenes>
<scene>
<name>Test1</name>
<image>assets/test1.png</image>
<triggerCondition>true</triggerCondition>
<drawPriority>1</drawPriority>
</scene>
<scene>
<name>Test2</name>
<image>assets/test2.png</image>
<name>Background</name>
<image>assets/checkered_tablecloth.jpg</image>
<triggerCondition>true</triggerCondition>
<drawPriority>1</drawPriority>
</scene>
......
......@@ -27,10 +27,10 @@ cursor.id.remapping.constant = 1024
adapter.class = lu.list.itis.dkd.tui.adapter.TuioAdapter
# The location and name of the root bootstrapping file.
bootstrapping.root = food_scenario.xml
bootstrapping.root = test_scenario.xml
# Properties for the equation system
scriptEngine.executable = C:/Octave/Octave-3.8.2/bin/octave.exe
scriptEngine.workingDir = model
equation.system = food_scenario.xml
scenario.description = food_scenario.xml
\ No newline at end of file
equation.system = test_scenario.xml
scenario.description = test_scenario.xml
\ No newline at end of file
......@@ -37,10 +37,18 @@ import org.jdom2.Element;
import java.awt.Graphics2D;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedHashSet;
import javax.imageio.ImageIO;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.ImageIcon;
/**
......@@ -62,6 +70,9 @@ public class Scene extends Content {
private BooleanVariable triggerVariable = new BooleanVariable("Trigger", "", false); //$NON-NLS-1$ //$NON-NLS-2$
/** The image to show when painting. */
private ImageIcon scenery;
/** The sound to play when painting. */
private Clip audioClip;
private boolean triggered = false;
/**
* Constructor initializing all fields.
......@@ -107,6 +118,34 @@ public class Scene extends Content {
} catch (final IOException ioe) {
throw new BuildException("The image could not be read!", ioe); //$NON-NLS-1$
}
// open the sound file as a Java input stream
try {
final Element soundNode = element.getChild(Externalization.SOUND_NODE);
if (null != soundNode) {
final File audioFile = new File(soundNode.getText());
final AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
final AudioFormat format = audioStream.getFormat();
final DataLine.Info info = new DataLine.Info(Clip.class, format);
audioClip = (Clip) AudioSystem.getLine(info);
audioClip.open(audioStream);
}
}
catch (final FileNotFoundException e) {
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) {
throw new BuildException("The sound format is not supported!", e); //$NON-NLS-1$
} catch (final LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Equation getTrigger() {
......@@ -115,6 +154,11 @@ public class Scene extends Content {
public boolean evaluateTrigger() {
trigger.evaluate();
if (!triggerVariable.getValue() && triggered) {
triggered = false;
}
return triggerVariable.getValue();
}
......@@ -123,6 +167,13 @@ public class Scene extends Content {
public void paint(Graphics2D canvas) {
// canvas.drawImage(scenery, 0, 0, null);
scenery.paintIcon(null, canvas, 0, 0);
if ((!triggered) && (audioClip != null)) {
audioClip.setFramePosition(0);
audioClip.start();
triggered = true;
}
}
......
This diff is collapsed.
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