Author: fdesbois Date: 2012-09-05 16:04:06 +0200 (Wed, 05 Sep 2012) New Revision: 525 Url: http://forge.codelutin.com/repositories/revision/sammoa/525 Log: refs #1197 : integration of audio reader / recorder Added: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java Removed: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioTest.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SoundPlayer.java Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManagerProvider.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioReader.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioReaderMock.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioReader.java trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUI.css trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUI.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManagerProvider.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManagerProvider.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/DeviceManagerProvider.java 2012-09-05 14:04:06 UTC (rev 525) @@ -29,9 +29,10 @@ import com.google.common.collect.Sets; import fr.ulr.sammoa.application.SammoaServiceSupport; import fr.ulr.sammoa.application.device.audio.AudioConfig; +import fr.ulr.sammoa.application.device.audio.AudioPositionListener; import fr.ulr.sammoa.application.device.audio.AudioReader; -import fr.ulr.sammoa.application.device.audio.AudioReaderMock; import fr.ulr.sammoa.application.device.audio.AudioRecorder; +import fr.ulr.sammoa.application.device.audio.SammoaAudioReader; import fr.ulr.sammoa.application.device.audio.SammoaAudioRecorder; import fr.ulr.sammoa.application.device.gps.GpsConfig; import fr.ulr.sammoa.application.device.gps.GpsHandler; @@ -151,7 +152,7 @@ @Override public AudioRecorder get() { -// return new AudioRecorderDefault(); +// return new AudioRecorderDefault(config); return new SammoaAudioRecorder(config); } }); @@ -163,13 +164,30 @@ AudioReader oldInstance = getDeviceManager(AudioReader.class); + Set<AudioPositionListener> positionListeners; + if (oldInstance != null) { + + // Remove all existing listeners and keep them for the new instance + positionListeners = Sets.newHashSet(oldInstance.getAudioPositionListeners()); + for (AudioPositionListener listener : positionListeners) { + oldInstance.removeAudioPositionListener(listener); + } + + } else { + positionListeners = Sets.newHashSet(); + } + AudioReader result = newDeviceManager(oldInstance, new Supplier<AudioReader>() { @Override public AudioReader get() { - return new AudioReaderMock(config); + return new SammoaAudioReader(); } }); + + for (AudioPositionListener listener : positionListeners) { + result.addAudioPositionListener(listener); + } return result; } Added: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java (rev 0) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java 2012-09-05 14:04:06 UTC (rev 525) @@ -0,0 +1,23 @@ +package fr.ulr.sammoa.application.device.audio; + +/** + * Permet de se mettre listener sur l'avancement de la lecture du fichier + * <p/> + * Created: 05/09/12 + * + * @author fdesbois <florian.desbois@codelutin.com> + */ +public interface AudioPositionListener { + + /** + * @param source La source de l'evenement + * @param audioPosition la nouvelle position en milliseconds + */ + public void positionChanged(AudioReader source, long audioPosition); + + /** + * @param source La source de l'evenement + * @param audioLength la nouvelle taille en milliseconds + */ + public void audioChanged(AudioReader source, long audioLength); +} Property changes on: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioPositionListener.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioReader.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioReader.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioReader.java 2012-09-05 14:04:06 UTC (rev 525) @@ -27,6 +27,7 @@ import javax.sound.sampled.AudioFileFormat; import java.io.File; +import java.util.Set; /** * Created: 21/08/12 @@ -53,4 +54,9 @@ /** @return current audio position in milliseconds */ long getPosition(); + void addAudioPositionListener(AudioPositionListener listener); + + void removeAudioPositionListener(AudioPositionListener listener); + + Set<AudioPositionListener> getAudioPositionListeners(); } Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioReaderMock.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioReaderMock.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioReaderMock.java 2012-09-05 14:04:06 UTC (rev 525) @@ -32,6 +32,7 @@ import javax.sound.sampled.AudioFileFormat; import java.io.File; +import java.util.HashSet; import java.util.Set; /** @@ -48,6 +49,7 @@ protected DeviceState state = DeviceState.UNAVAILABLE; protected Set<DeviceStateListener> listeners = Sets.newHashSet(); + protected Set<AudioPositionListener> audioPositionListener = new HashSet<AudioPositionListener>(); public AudioReaderMock(AudioConfig config) { this.config = config; @@ -140,4 +142,19 @@ public Set<DeviceStateListener> getDeviceStateListeners() { return listeners; } + + @Override + public void addAudioPositionListener(AudioPositionListener listener) { + audioPositionListener.add(listener); + } + + @Override + public void removeAudioPositionListener(AudioPositionListener listener) { + audioPositionListener.remove(listener); + } + + @Override + public Set<AudioPositionListener> getAudioPositionListeners() { + return audioPositionListener; + } } Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioRecorderDefault.java 2012-09-05 14:04:06 UTC (rev 525) @@ -115,6 +115,7 @@ DEFAULT_BIG_ENDIAN ), DEFAULT_OUTPUT_TYPE); + this.config = config; } public AudioRecorderDefault(AudioFormat audioFormat, Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioTest.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioTest.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioTest.java 2012-09-05 14:04:06 UTC (rev 525) @@ -1,328 +0,0 @@ -package fr.ulr.sammoa.application.device.audio; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.UnsupportedAudioFileException; -import javax.swing.BorderFactory; -import javax.swing.Box; -import javax.swing.ButtonGroup; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Petite application de test de l'audio. Elle permet de choisir differente - * configuration audio. De faire des enregistrements et de relire le fichier - * enregistre. - * <p> - * La configuration choisi est inscrite et permet de la copier dans le fichier - * de configuration - * <p> - * Si la machine ne supporte pas deux enregistrement simultane, delay est mis - * a 0. - * - * Created: 27 aout 2012 - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class AudioTest extends JFrame { - - private static final Logger logger = LoggerFactory.getLogger(AudioTest.class); - - protected SammoaAudioRecorder recorder; - /** delay par defaut de chevauchement d'enregistrement */ - protected int delay = 0; - - protected JTextField filenameField = new JTextField("/tmp/junkk.wav"); - protected JTextArea informationArea = new JTextArea(); - - protected JButton captureBtn = new JButton("Capture"); - protected JButton stopBtn = new JButton("Stop"); - protected JButton loadBtn = new JButton("Load"); - protected SoundPlayer playerPanel = new SoundPlayer(); - - protected JPanel btnPanelSampleRate = new JPanel(); - protected ButtonGroup btnGroupSampleRate = new ButtonGroup(); - JRadioButton[] btnSampleRate = new JRadioButton[]{ - new JRadioButton("8000",true), - new JRadioButton("11025"), - new JRadioButton("16000"), - new JRadioButton("22050"), - new JRadioButton("44100") - }; - - protected JPanel btnPanelSampleSizeInBits = new JPanel(); - protected ButtonGroup btnGroupSampleSizeInBits = new ButtonGroup(); - JRadioButton[] btnSampleSizeInBits = new JRadioButton[]{ - new JRadioButton("8"), - new JRadioButton("16",true) - }; - - public AudioTest(){//constructor - initUI(); - testMultiRecord(); - } - - protected void initUI () { - Box buttons = Box.createHorizontalBox(); - buttons.add(captureBtn); - buttons.add(stopBtn); - - Box box = Box.createVerticalBox(); - box.add(filenameField); - box.add(buttons); - - for (JRadioButton b : btnSampleRate) { - //Include the radio buttons in a group - btnGroupSampleRate.add(b); - //Add the radio buttons to the JPanel - btnPanelSampleRate.add(b); - b.addActionListener( - new ActionListener(){ - public void actionPerformed( - ActionEvent e){ - updateConfigInfo(); - } - }); - } - - //Put the JPanel in the JFrame - box.add(btnPanelSampleRate); - - for (JRadioButton b : btnSampleSizeInBits) { - //Include the radio buttons in a group - btnGroupSampleSizeInBits.add(b); - //Add the radio buttons to the JPanel - btnPanelSampleSizeInBits.add(b); - b.addActionListener( - new ActionListener(){ - public void actionPerformed( - ActionEvent e){ - updateConfigInfo(); - } - }); - } - - //Put the JPanel in the JFrame - box.add(btnPanelSampleSizeInBits); - - informationArea.setBorder(BorderFactory.createRaisedBevelBorder()); - informationArea.setLineWrap(true); - box.add(informationArea); - box.add(loadBtn); - box.add(playerPanel); - - //Finish the GUI and make visible - setTitle("Sound Test"); - setDefaultCloseOperation(EXIT_ON_CLOSE); - getContentPane().add(box, "Center"); - pack(); - setVisible(true); - - captureBtn.setEnabled(true); - stopBtn.setEnabled(false); - - // ADD LISTENER - - //Register anonymous listeners - captureBtn.addActionListener( - new ActionListener(){ - public void actionPerformed( - ActionEvent e){ - captureBtn.setEnabled(false); - stopBtn.setEnabled(true); - captureAudio(); - } - }); - - stopBtn.addActionListener( - new ActionListener(){ - public void actionPerformed( - ActionEvent e){ - captureBtn.setEnabled(true); - stopBtn.setEnabled(false); - recorder.stop(); - } - }); - - loadBtn.addActionListener( - new ActionListener(){ - public void actionPerformed( - ActionEvent e){ - File file = new File(filenameField.getText()); - playerPanel.loadFile(file); - } - }); - } - - protected void captureAudio(){ - try{ - File file = new File(filenameField.getText()); - recorder = new SammoaAudioRecorder(getSampleRate(), getSampleSizeInBits(), 0); - recorder.record(file, true); - }catch (Exception eee) { - logger.error("Can't capture audio", eee); - } - } - - protected float getSampleRate() { - float result = 44100; - for (JRadioButton b : btnSampleRate) { - if (b.isSelected()) { - result = Float.parseFloat(b.getText()); - } - } - return result; - } - - protected int getSampleSizeInBits() { - int result = 44100; - for (JRadioButton b : btnSampleSizeInBits) { - if (b.isSelected()) { - result = Integer.parseInt(b.getText()); - } - } - return result; - } - - protected void updateConfigInfo() { - informationArea.setText(String.format( - "sammoa.audio.recordDelayInSeconds=%s\n" - + "sammoa.audio.sampleRate=%s\n" - + "sammoa.audio.sampleSizeInBits=%s\n", - delay, getSampleRate(), getSampleSizeInBits())); - } - - protected void testMultiRecord() { - try { - File f1 = File.createTempFile("sammoa-test-", ".wav"); - f1.deleteOnExit(); - File f2 = File.createTempFile("sammoa-test-", ".wav"); - f2.deleteOnExit(); - - SammoaAudioRecorder r1 = new SammoaAudioRecorder(8000, 16, 2); - r1.record(f1, true); - - SammoaAudioRecorder r2 = new SammoaAudioRecorder(8000, 16, 2); - r2.record(f2, true); - - r2.stop(); - r1.stop(); - delay = 5; - } catch(Exception eee) { - logger.error("Can't record multiple file in same time", eee); - delay = 0; - } - updateConfigInfo(); - } - - - public static void main( String args[]) - throws LineUnavailableException, UnsupportedAudioFileException, IOException { - new AudioTest(); - -// float sampleRate = 8000; // 8000,11025,16000,22050,44100 -// int sampleSizeInBits = 16; // 8,16 -// -// int channels = 1; // 1,2 -// boolean signed = true; //true,false -// boolean bigEndian = false; //true,false -// -// AudioFormat audioFormat = new AudioFormat( -// sampleRate, -// sampleSizeInBits, -// channels, -// signed, -// bigEndian); -// -// DataLine.Info dataLineInfo = new DataLine.Info( -// TargetDataLine.class, audioFormat); -// { -// TargetDataLine l1 = (TargetDataLine)AudioSystem.getLine(dataLineInfo); -// System.out.println("Line: " + l1); -// System.out.println("Line: " + l1.getLineInfo()); -// l1.open(audioFormat); -// l1.start(); -// -// TargetDataLine l2 = (TargetDataLine)AudioSystem.getLine(dataLineInfo); -// System.out.println("Line: " + l2); -// System.out.println("Line: " + l2.getLineInfo()); -// l2.open(audioFormat); -// l1.start(); -// } -// { -// AudioFileFormat aff = AudioSystem.getAudioFileFormat(new File("/tmp/junkk.wav")); -// System.out.println("File: "+ aff.toString()); -// AudioInputStream sourceAis = AudioSystem.getAudioInputStream(new File("/tmp/junkk.wav")); -// -// DataLine.Info clipInfo = new DataLine.Info(Clip.class, audioFormat); -// Clip clip = (Clip)AudioSystem.getLine(clipInfo); -// -// AudioInputStream ais = AudioSystem.getAudioInputStream(audioFormat, sourceAis); -//// clip.open(ais); -//// clip.start(); -// } -// { -// File f = new File("/tmp/junkk.wav"); -// Player p = Manager.createRealizedPlayer(f.toURI().toURL()); -// p.start(); -//// p.set -// } -// -// System.out.println("#############################################"); -// Line.Info[] sources = AudioSystem.getSourceLineInfo(new Line.Info(SourceDataLine.class)); -// Line.Info[] target = AudioSystem.getTargetLineInfo(new Line.Info(TargetDataLine.class)); -// -// System.out.println("AudioFileTypes:" + Arrays.toString(AudioSystem.getAudioFileTypes())); -// -// System.out.println("mixer:" + Arrays.toString(AudioSystem.getMixerInfo())); -// for(Mixer.Info i : AudioSystem.getMixerInfo()) { -// Mixer mixer = AudioSystem.getMixer(i); -// System.out.println("-----"); -// System.out.println("mixer:" + mixer + "("+mixer.isLineSupported(Port.Info.MICROPHONE)+")"); -// try { -// mixer.open(); -// } catch (LineUnavailableException eee) { -// System.out.println("Can't open mixer"); -// } -// System.out.println("mixer:" + mixer + "("+mixer.isLineSupported(Port.Info.MICROPHONE)+")"); -// -// System.out.println("mixer info: " + mixer.getLineInfo()); -// System.out.println("max line: " + mixer.getMaxLines(mixer.getLineInfo())); -// -// for (Line.Info li : mixer.getSourceLineInfo()) { -// System.out.println("s line info: " + li + "("+mixer.getMaxLines(li)+")"); -// System.out.println("s line info: " + li.getLineClass()); -// } -// -// for (Line.Info li : mixer.getTargetLineInfo()) { -// System.out.println("t line info: " + li + "("+mixer.getMaxLines(li)+")"); -// System.out.println("t line info: " + li.getLineClass()); -// } -// -// for (Line l : mixer.getSourceLines()) { -// System.out.println("s line: " + l); -// System.out.println("s line info: " + l.getLineInfo()); -// } -// for (Line l : mixer.getTargetLines()) { -// System.out.println("t line: " + l); -// System.out.println("t line info: " + l.getLineInfo()); -// } -// } -// System.out.println("sources: " + Arrays.toString(sources)); -// System.out.println("target: " + Arrays.toString(target)); - - } -} \ No newline at end of file Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioReader.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioReader.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SammoaAudioReader.java 2012-09-05 14:04:06 UTC (rev 525) @@ -28,19 +28,20 @@ import fr.ulr.sammoa.application.device.DeviceStateEvent; import fr.ulr.sammoa.application.device.DeviceStateListener; import fr.ulr.sammoa.application.device.DeviceTechnicalException; -import java.io.File; -import java.util.HashSet; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import javax.sound.sampled.AudioFileFormat; 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 org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.io.File; +import java.util.HashSet; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; /** * Classe permettant la lecture d'un fichier audio, et de ce deplace a une @@ -72,18 +73,6 @@ protected Set<AudioPositionListener> audioPositionListener = new HashSet<AudioPositionListener>(); /** - * Permet de se mettre listener sur l'avancement de la lecture du fichier - */ - static public interface AudioPositionListener { - /** - * - * @param source La source de l'evenement - * @param audioPosition la nouvelle position en milliseconds - */ - public void positionChange(Object source, long audioPosition); - } - - /** * Classe servant a surveiller l'avancement de la lecture * et a prevenir les listeners */ @@ -113,7 +102,7 @@ long position = reader.getClip().getMicrosecondPosition()/1000L; if (old != position) { reader.audioPosition = position; - reader.firePositionChange(position); + reader.firePositionChanged(position); } } else { reader.stop(); @@ -189,6 +178,7 @@ } // Get the clip length in microseconds and convert to milliseconds audioLength = (int)(clip.getMicrosecondLength( )/1000); + fireAudioChanged(audioLength); setState(DeviceState.READY); logger.debug(String.format("Sound file '%s' loaded", file)); @@ -221,17 +211,23 @@ this.audioPosition = position; if (old != position ) { clip.setMicrosecondPosition(position * 1000L); - firePositionChange(position); + firePositionChanged(position); } } } - protected void firePositionChange(long position) { + protected void firePositionChanged(long position) { for (AudioPositionListener l : audioPositionListener) { - l.positionChange(this, position); + l.positionChanged(this, position); } } + protected void fireAudioChanged(long length) { + for (AudioPositionListener l : audioPositionListener) { + l.audioChanged(this, length); + } + } + @Override public long getPosition() { return audioPosition; @@ -302,14 +298,17 @@ return listeners; } + @Override public void addAudioPositionListener(AudioPositionListener listener) { audioPositionListener.add(listener); } + @Override public void removeAudioPositionListener(AudioPositionListener listener) { audioPositionListener.remove(listener); } + @Override public Set<AudioPositionListener> getAudioPositionListeners() { return audioPositionListener; } Deleted: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SoundPlayer.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SoundPlayer.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SoundPlayer.java 2012-09-05 14:04:06 UTC (rev 525) @@ -1,225 +0,0 @@ -package fr.ulr.sammoa.application.device.audio; - -import fr.ulr.sammoa.application.device.DeviceState; -import fr.ulr.sammoa.application.device.DeviceStateEvent; -import fr.ulr.sammoa.application.device.DeviceStateListener; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.io.File; -import java.io.IOException; -import javax.sound.sampled.LineUnavailableException; -import javax.sound.sampled.UnsupportedAudioFileException; -import javax.swing.Box; -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JSlider; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; - -/** - * Composant qui permet de charge un fichier audio et de le jouer. On peut se - * placer ou l'on veut dans le fichier audio. - * - * usage: - * <li> SoundPlayer sp = new SoundPlayer(); - * <li> panel.add(sp); - * <li> sp.load(myFileWav); - * - * Created: 03 septembre 2012 - * - * @author Benjamin POUSSIN <poussin@codelutin.com> - * @version $Revision$ - * - * Last update: $Date$ - * by : $Author$ - */ -public class SoundPlayer extends JComponent implements DeviceStateListener { - protected SammoaAudioReader reader; - protected boolean playing = false; // whether the sound is currently playing - - // The following fields are for the GUI - protected JButton play; // The Play/Stop button - protected JSlider progress; // Shows and sets current position in sound - protected JLabel time; // Displays audioPosition as a number - protected JLabel maxTime; - - // Create a SoundPlayer component for the specified file. - public SoundPlayer() { - initUI(); - initAudio(); - } - - protected void initUI() { - // Now create the basic GUI - play = new JButton("Play"); // Play/stop button - progress = new JSlider(0, 0, 0); // Shows position in sound - progress.setMajorTickSpacing(60000); - progress.setMinorTickSpacing(10000); - progress.setPaintTicks(true); - progress.setPaintLabels(true); - - time = new JLabel("0"); // Shows position as a # - maxTime = new JLabel("/0"); // Shows position as a # - - // put those controls in a row - Box row = Box.createHorizontalBox( ); - row.add(play); - row.add(progress); - row.add(time); - row.add(maxTime); - - // And add them to this component. - setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); - this.add(row); - - // ADD LISTENER - - // When clicked, start or stop playing the sound - play.addActionListener(new ActionListener( ) { - public void actionPerformed(ActionEvent e) { - if (playing) { - stop( ); - } else { - play( ); - } - } - }); - - progress.addMouseListener(new MouseAdapter() { - boolean inPlay = false; - - @Override - public void mousePressed(MouseEvent e) { - inPlay= playing; - if (inPlay) { - reader.stop(); - } - } - - @Override - public void mouseReleased(MouseEvent e) { - int value = progress.getValue( ); - // Update the time label - time.setText(value/1000 + "." + (value%1000)/100); - // If we're not already there, skip there. - if (value >= 0 && value <= reader.getLength()) { - reader.setPosition(value); - } - - if (inPlay) { - reader.start(); - } - } - }); - - // Whenever the slider value changes, update the time label. - progress.addChangeListener(new ChangeListener( ) { - public void stateChanged(ChangeEvent e) { - int value = progress.getValue( ); - time.setText(value/1000 + "." + (value%1000)/100); - } - }); - } - - protected void initAudio() { - reader = new SammoaAudioReader(); - reader.addDeviceStateListener(this); - // on se met listener de l'avancee de la lecture - reader.addAudioPositionListener(new SammoaAudioReader.AudioPositionListener() { - public void positionChange(Object source, long audioPosition) { - progress.setValue((int)audioPosition); - } - }); - - } - - public void stateChanged(DeviceStateEvent event) { - DeviceState state = event.getNewValue(); - if (state == DeviceState.RUNNING) { - this.playing = true; - play.setText("Stop"); - } else { - this.playing = false; - play.setText("Play"); - } - } - - /** - * Charge un nouveau fichier - * @param f le fichier a charger - */ - public void loadFile(File f) { - getAudioReader().load(f); - long value = getLength(); - progress.setMaximum((int)value); - maxTime.setText("/" + value/1000 + "." + (value%1000)/100); - } - - /** - * retourne le lecture utilise par ce composant - * @return - */ - public SammoaAudioReader getAudioReader() { - return reader; - } - - /** - * Donne la position actuelle de la lecture en milliseconde - * @return - */ - public long getPosition() { - return getAudioReader().getPosition(); - } - - /** - * Donne la longueur total du fichier en milliseconde - * @return - */ - public long getLength() { - return getAudioReader().getLength(); - } - - /** - * Start playing the sound at the current position - */ - public void play() { - getAudioReader().start(); - } - - /** - * Stop playing the sound, but retain the current position - */ - public void stop() { - getAudioReader().stop(); - } - - // The main method just creates a SoundPlayer in a Frame and displays it - public static void main(String[] args) - throws IOException, UnsupportedAudioFileException, LineUnavailableException { - SoundPlayer player; - - File file; - if (args.length == 0) { - file = new File("/tmp/junkk1.wav"); - } else { - file = new File(args[0]); - } - - // Create a SoundPlayer object to play the sound. - player = new SoundPlayer(); - player.loadFile(file); - - // Put it in a window and play it - JFrame f = new JFrame("SoundPlayer"); - f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - f.getContentPane().add(player, "Center"); - f.pack(); - f.setVisible(true); - } - -} \ No newline at end of file Modified: trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java =================================================================== --- trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/flightController/FlightControllerValidation.java 2012-09-05 14:04:06 UTC (rev 525) @@ -87,17 +87,18 @@ DateTime previousTime = Dates.toDateTime(currentRoute.getBeginTime()); + int position = (int) getAudioReader().getPosition() / 1000; + if (logger.isDebugEnabled()) { - logger.debug(String.format("Get location after previousTime %1$tH:%1$tM:%1$tS.%1$tL", - previousTime.toDate()) + logger.debug(String.format("Get location after previousTime %1$tH:%1$tM:%1$tS.%1$tL (audio position = %2$d)", + previousTime.toDate(), + position) ); } - long position = getAudioReader().getPosition(); - DateTime newTime; if (position > 0) { - newTime = previousTime.plus(position); + newTime = previousTime.plusSeconds(position); } else { newTime = new DateTime(previousTime); Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java (from rev 524, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/AudioTest.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java 2012-09-05 14:04:06 UTC (rev 525) @@ -0,0 +1,258 @@ +package fr.ulr.sammoa.ui.swing; + +import com.google.common.base.Throwables; +import fr.ulr.sammoa.application.device.audio.SammoaAudioRecorder; +import fr.ulr.sammoa.ui.swing.flight.bar.SoundPlayer; +import fr.ulr.sammoa.ui.swing.util.SammoaUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.IOException; +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JTextArea; +import javax.swing.JTextField; + +//import javax.media.CannotRealizeException; +//import javax.media.NoPlayerException; + +/** + * Petite application de test de l'audio. Elle permet de choisir differente + * configuration audio. De faire des enregistrements et de relire le fichier + * enregistre. + * <p> + * La configuration choisi est inscrite et permet de la copier dans le fichier + * de configuration + * <p> + * Si la machine ne supporte pas deux enregistrement simultane, delay est mis + * a 0. + * + * Created: 27 aout 2012 + * + * @author Benjamin POUSSIN <poussin@codelutin.com> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class AudioCheck extends JFrame { + + private static final Logger logger = LoggerFactory.getLogger(AudioCheck.class); + + protected SammoaAudioRecorder recorder; + /** delay par defaut de chevauchement d'enregistrement */ + protected int delay = 0; + + protected JTextField filenameField = new JTextField("/tmp/junkk.wav"); + protected JTextArea informationArea = new JTextArea(); + + protected JButton captureBtn = new JButton("Capture"); + protected JButton stopBtn = new JButton("Stop"); + protected JButton loadBtn = new JButton("Load"); + protected SoundPlayer playerPanel = new SoundPlayer(); + + protected JPanel btnPanelSampleRate = new JPanel(); + protected ButtonGroup btnGroupSampleRate = new ButtonGroup(); + JRadioButton[] btnSampleRate = new JRadioButton[]{ + new JRadioButton("8000",true), + new JRadioButton("11025"), + new JRadioButton("16000"), + new JRadioButton("22050"), + new JRadioButton("44100") + }; + + protected JPanel btnPanelSampleSizeInBits = new JPanel(); + protected ButtonGroup btnGroupSampleSizeInBits = new ButtonGroup(); + JRadioButton[] btnSampleSizeInBits = new JRadioButton[]{ + new JRadioButton("8"), + new JRadioButton("16",true) + }; + + public AudioCheck(){//constructor + initUI(); + checkMultiRecord(); + } + + protected void initUI () { + Box buttons = Box.createHorizontalBox(); + buttons.add(captureBtn); + buttons.add(stopBtn); + + Box box = Box.createVerticalBox(); + box.add(filenameField); + box.add(buttons); + + for (JRadioButton b : btnSampleRate) { + //Include the radio buttons in a group + btnGroupSampleRate.add(b); + //Add the radio buttons to the JPanel + btnPanelSampleRate.add(b); + b.addActionListener( + new ActionListener(){ + public void actionPerformed( + ActionEvent e){ + updateConfigInfo(); + } + }); + } + + //Put the JPanel in the JFrame + box.add(btnPanelSampleRate); + + for (JRadioButton b : btnSampleSizeInBits) { + //Include the radio buttons in a group + btnGroupSampleSizeInBits.add(b); + //Add the radio buttons to the JPanel + btnPanelSampleSizeInBits.add(b); + b.addActionListener( + new ActionListener(){ + public void actionPerformed( + ActionEvent e){ + updateConfigInfo(); + } + }); + } + + //Put the JPanel in the JFrame + box.add(btnPanelSampleSizeInBits); + + informationArea.setBorder(BorderFactory.createRaisedBevelBorder()); + informationArea.setLineWrap(true); + box.add(informationArea); + box.add(loadBtn); + box.add(playerPanel); + + //Finish the GUI and make visible + setTitle("Sound Test"); + setDefaultCloseOperation(EXIT_ON_CLOSE); + getContentPane().add(box, "Center"); + pack(); + setVisible(true); + + captureBtn.setEnabled(true); + stopBtn.setEnabled(false); + + // ADD LISTENER + + //Register anonymous listeners + captureBtn.addActionListener( + new ActionListener(){ + public void actionPerformed( + ActionEvent e){ + captureBtn.setEnabled(false); + stopBtn.setEnabled(true); + captureAudio(); + } + }); + + stopBtn.addActionListener( + new ActionListener(){ + public void actionPerformed( + ActionEvent e){ + captureBtn.setEnabled(true); + stopBtn.setEnabled(false); + recorder.stop(); + } + }); + + loadBtn.addActionListener( + new ActionListener(){ + public void actionPerformed( + ActionEvent e){ + File file = new File(filenameField.getText()); + playerPanel.loadFile(file); + } + }); + } + + protected void captureAudio(){ + try{ + File file = new File(filenameField.getText()); + recorder = new SammoaAudioRecorder(getSampleRate(), getSampleSizeInBits(), 0); + recorder.record(file, true); + }catch (Exception eee) { + logger.error("Can't capture audio", eee); + } + } + + protected float getSampleRate() { + float result = 44100; + for (JRadioButton b : btnSampleRate) { + if (b.isSelected()) { + result = Float.parseFloat(b.getText()); + } + } + return result; + } + + protected int getSampleSizeInBits() { + int result = 44100; + for (JRadioButton b : btnSampleSizeInBits) { + if (b.isSelected()) { + result = Integer.parseInt(b.getText()); + } + } + return result; + } + + protected void updateConfigInfo() { + informationArea.setText(String.format( + "sammoa.audio.recordDelayInSeconds=%s\n" + + "sammoa.audio.sampleRate=%s\n" + + "sammoa.audio.sampleSizeInBits=%s\n", + delay, getSampleRate(), getSampleSizeInBits())); + } + + protected void checkMultiRecord() { + SammoaAudioRecorder r1 = new SammoaAudioRecorder(8000, 16, 2); + SammoaAudioRecorder r2 = new SammoaAudioRecorder(8000, 16, 2); + try { + File f1 = File.createTempFile("sammoa-audioCheck-", ".wav"); + f1.deleteOnExit(); + File f2 = File.createTempFile("sammoa-audioCheck-", ".wav"); + f2.deleteOnExit(); + + r1.record(f1, true); + + r2.record(f2, true); + + r1.stop(); + r2.stop(); + delay = 5; + SammoaUtil.showSuccessMessage(this, "The recording delay is set to " + + "5 seconds between each recording, " + + "you can update this value from" + + " configuration interface"); + } catch(IOException ex) { + throw Throwables.propagate(ex); + + } catch(LineUnavailableException ex) { + delay = 0; + logger.error("Can't record multiple file in same time", ex); + SammoaUtil.showErrorMessage(this, "Can't record multiple file in " + + "same time, 0 second delay " + + "between recording must be used"); + + } finally { + r1.close(); + r2.close(); + } + updateConfigInfo(); + } + + + public static void main( String args[]) + throws LineUnavailableException, UnsupportedAudioFileException, IOException { + new AudioCheck(); + } +} \ No newline at end of file Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/AudioCheck.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUI.css =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUI.css 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUI.css 2012-09-05 14:04:06 UTC (rev 525) @@ -40,13 +40,20 @@ mnemonic:C; } -#menuHome { +#menuFileHome { text:"sammoa.action.home"; toolTipText:"sammoa.action.home.tip"; actionIcon:"home"; mnemonic:H; } +#menuFileAudioCheck { + text:"sammoa.action.audioCheck"; + toolTipText:"sammoa.action.audioCheck.tip"; + actionIcon:"sound"; + mnemonic:A; +} + #exit { text:"sammoa.menu.exit"; toolTipText:"sammoa.menu.help.tip"; Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUI.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUI.jaxx 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUI.jaxx 2012-09-05 14:04:06 UTC (rev 525) @@ -56,10 +56,12 @@ <!-- menu --> <JMenuBar id='menu'> <JMenu id='menuFile'> - <JMenuItem id='menuHome' + <JMenuItem id='menuFileHome' onActionPerformed="getHandler().showHome()"/> <JMenuItem id='menuFileConfiguration' onActionPerformed="getHandler().showConfig()"/> + <JMenuItem id='menuFileAudioCheck' + onActionPerformed="getHandler().showAudioCheck()"/> <JSeparator/> <JMenuItem id='exit' onActionPerformed='getHandler().closeSammoa()'/> Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/MainUIHandler.java 2012-09-05 14:04:06 UTC (rev 525) @@ -427,6 +427,10 @@ helper.displayUI(ui, false); } + public void showAudioCheck() { + new AudioCheck(); + } + /** * Reload the given device identified by its {@code deviceManagerClass} for * {@code ui}. Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.css 2012-09-05 14:04:06 UTC (rev 525) @@ -99,3 +99,7 @@ #lblSpeed { text: {model.getSpeed()}; } + +#soundPlayer { + enabled: {flightUIModel.getTransectFlightEditBean() != null}; +} Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBar.jaxx 2012-09-05 14:04:06 UTC (rev 525) @@ -51,15 +51,15 @@ <Table id='validationBar'> <row> - <cell fill='horizontal' weightx='0.2'> +<!-- <cell fill='horizontal' weightx='0.2'> <JPanel id='audioButtonPanel' layout='{new BoxLayout(audioButtonPanel, BoxLayout.X_AXIS)}'> <JButton id='startAudioButton'/> <JButton id='stopAudioButton'/> </JPanel> - </cell> + </cell>--> <cell fill='horizontal'> - <JSlider id='audioSlider' enabled='false'/> + <SoundPlayer id='soundPlayer'/> </cell> <cell fill='horizontal' weightx='0.2'> <JPanel id='validButtonPanel' Modified: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/FlightBarHandler.java 2012-09-05 14:04:06 UTC (rev 525) @@ -24,6 +24,7 @@ */ package fr.ulr.sammoa.ui.swing.flight.bar; +import fr.ulr.sammoa.application.device.audio.AudioReader; import fr.ulr.sammoa.application.device.audio.AudioRecorder; import fr.ulr.sammoa.application.device.gps.GpsHandler; import fr.ulr.sammoa.application.flightController.FlightController; @@ -72,12 +73,17 @@ if (flightUIModel.isValidationMode()) { // Put actionName for validation buttons - ui.getStartAudioButton().putClientProperty("actionName", "startAudio"); - ui.getStopAudioButton().putClientProperty("actionName", "stopAudio"); +// ui.getStartAudioButton().putClientProperty("actionName", "startAudio"); +// ui.getStopAudioButton().putClientProperty("actionName", "stopAudio"); ui.getValidObservationButton().putClientProperty("actionName", "validObservation"); ui.getValidRouteButton().putClientProperty("actionName", "validRoute"); ui.getValidTransectButton().putClientProperty("actionName", "validTransect"); + AudioReader audioReader = flightController.getDeviceManager(AudioReader.class); + ui.getSoundPlayer().setReader(audioReader); + audioReader.addDeviceStateListener(ui.getSoundPlayer()); + audioReader.addAudioPositionListener(ui.getSoundPlayer()); + } else { // Remove the bar used only for validation Copied: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java (from rev 524, trunk/sammoa-application/src/main/java/fr/ulr/sammoa/application/device/audio/SoundPlayer.java) =================================================================== --- trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java (rev 0) +++ trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java 2012-09-05 14:04:06 UTC (rev 525) @@ -0,0 +1,233 @@ +package fr.ulr.sammoa.ui.swing.flight.bar; + +import fr.ulr.sammoa.application.device.DeviceState; +import fr.ulr.sammoa.application.device.DeviceStateEvent; +import fr.ulr.sammoa.application.device.DeviceStateListener; +import fr.ulr.sammoa.application.device.audio.AudioPositionListener; +import fr.ulr.sammoa.application.device.audio.AudioReader; +import fr.ulr.sammoa.application.device.audio.SammoaAudioReader; + +import javax.sound.sampled.LineUnavailableException; +import javax.sound.sampled.UnsupportedAudioFileException; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JSlider; +import javax.swing.event.ChangeEvent; +import javax.swing.event.ChangeListener; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.io.File; +import java.io.IOException; + +/** + * Composant qui permet de charge un fichier audio et de le jouer. On peut se + * placer ou l'on veut dans le fichier audio. + * + * usage: + * <li> SoundPlayer sp = new SoundPlayer(); + * <li> panel.add(sp); + * <li> sp.load(myFileWav); + * + * Created: 03 septembre 2012 + * + * @author Benjamin POUSSIN <poussin@codelutin.com> + * @version $Revision$ + * + * Last update: $Date$ + * by : $Author$ + */ +public class SoundPlayer extends JComponent implements DeviceStateListener, AudioPositionListener { + protected AudioReader reader; + protected boolean playing = false; // whether the sound is currently playing + + // The following fields are for the GUI + protected JButton play; // The Play/Stop button + protected JSlider progress; // Shows and sets current position in sound + protected JLabel time; // Displays audioPosition as a number + protected JLabel maxTime; + + // Create a SoundPlayer component for the specified file. + public SoundPlayer() { + initUI(); +// initAudio(); + } + + protected void initUI() { + // Now create the basic GUI + play = new JButton("Play"); // Play/stop button + progress = new JSlider(0, 0, 0); // Shows position in sound + progress.setMajorTickSpacing(60000); + progress.setMinorTickSpacing(10000); + progress.setPaintTicks(true); + progress.setPaintLabels(true); + + time = new JLabel("0"); // Shows position as a # + maxTime = new JLabel("/0"); // Shows position as a # + + // put those controls in a row + Box row = Box.createHorizontalBox( ); + row.add(play); + row.add(progress); + row.add(time); + row.add(maxTime); + + // And add them to this component. + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + this.add(row); + + // ADD LISTENER + + // When clicked, start or stop playing the sound + play.addActionListener(new ActionListener( ) { + public void actionPerformed(ActionEvent e) { + if (playing) { + stop( ); + } else { + play( ); + } + } + }); + + progress.addMouseListener(new MouseAdapter() { + boolean inPlay = false; + + @Override + public void mousePressed(MouseEvent e) { + inPlay= playing; + if (inPlay) { + reader.stop(); + } + } + + @Override + public void mouseReleased(MouseEvent e) { + int value = progress.getValue( ); + // Update the time label + time.setText(value/1000 + "." + (value%1000)/100); + // If we're not already there, skip there. + if (value >= 0 && value <= reader.getLength()) { + reader.setPosition(value); + } + + if (inPlay) { + reader.start(); + } + } + }); + + // Whenever the slider value changes, update the time label. + progress.addChangeListener(new ChangeListener( ) { + public void stateChanged(ChangeEvent e) { + int value = progress.getValue( ); + time.setText(value/1000 + "." + (value%1000)/100); + } + }); + } + + @Override + public void stateChanged(DeviceStateEvent event) { + DeviceState state = event.getNewValue(); + if (state == DeviceState.RUNNING) { + this.playing = true; + play.setText("Stop"); + } else { + this.playing = false; + play.setText("Play"); + } + } + + @Override + public void positionChanged(AudioReader source, long audioPosition) { + progress.setValue((int) audioPosition); + } + + @Override + public void audioChanged(AudioReader source, long audioLength) { + progress.setMaximum((int) audioLength); + maxTime.setText("/" + audioLength / 1000 + "." + (audioLength % 1000) / 100); + } + + /** + * Charge un nouveau fichier + * @param f le fichier a charger + */ + public void loadFile(File f) { + getAudioReader().load(f); + } + + public void setReader(AudioReader reader) { + this.reader = reader; + } + + /** + * retourne le lecture utilise par ce composant + * @return + */ + public AudioReader getAudioReader() { + return reader; + } + + /** + * Donne la position actuelle de la lecture en milliseconde + * @return + */ + public long getPosition() { + return getAudioReader().getPosition(); + } + + /** + * Donne la longueur total du fichier en milliseconde + * @return + */ + public long getLength() { + return getAudioReader().getLength(); + } + + /** + * Start playing the sound at the current position + */ + public void play() { + getAudioReader().start(); + } + + /** + * Stop playing the sound, but retain the current position + */ + public void stop() { + getAudioReader().stop(); + } + + // The main method just creates a SoundPlayer in a Frame and displays it + public static void main(String[] args) + throws IOException, UnsupportedAudioFileException, LineUnavailableException { + SoundPlayer player; + + File file; + if (args.length == 0) { + file = new File("/tmp/junkk.wav"); + } else { + file = new File(args[0]); + } + + // Create a SoundPlayer object to play the sound. + player = new SoundPlayer(); + AudioReader reader = new SammoaAudioReader(); + reader.addDeviceStateListener(player); + reader.addAudioPositionListener(player); + player.setReader(reader); + player.loadFile(file); + + // Put it in a window and play it + JFrame f = new JFrame("SoundPlayer"); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.getContentPane().add(player, "Center"); + f.pack(); + f.setVisible(true); + } +} \ No newline at end of file Property changes on: trunk/sammoa-ui-swing/src/main/java/fr/ulr/sammoa/ui/swing/flight/bar/SoundPlayer.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL Added: svn:eol-style + native Modified: trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties =================================================================== --- trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 2012-09-05 14:03:46 UTC (rev 524) +++ trunk/sammoa-ui-swing/src/main/resources/i18n/sammoa-ui-swing_en_GB.properties 2012-09-05 14:04:06 UTC (rev 525) @@ -4,6 +4,8 @@ sammoa.action.about=About sammoa.action.about.tip=About sammoa.action.add.tip=ADD \: create a new LEG route for the current Transect (the observation conditions have changed) +sammoa.action.audioCheck= +sammoa.action.audioCheck.tip= sammoa.action.begin=Begin sammoa.action.begin.tip=BEGIN \: begin effort to create a new LEG route for the next selected Transect sammoa.action.cancel=Cancel