Changeset 3962 in osm


Ignore:
Timestamp:
2007-08-05T21:54:03+02:00 (17 years ago)
Author:
christofd
Message:

moved resources into separate directory
made play sound in background thread

Location:
applications/editors/josm/plugins/surveyor
Files:
6 added
1 deleted
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/surveyor/build.xml

    r3790 r3962  
    1010         
    1111          <!-- plugin meta data (enter new version number if anything changed!) -->
    12           <property name="plugin.version" value="1.2"/>
     12          <property name="plugin.version" value="1.3.1"/>
    1313          <property name="plugin.description" value="Allow adding markers/nodes on current gps positions (V${plugin.version})."/>
    1414          <property name="plugin.stage" value="60"/>
     
    2424        <target name="dist" depends="compile,site">
    2525                <!-- images -->
    26                 <copy todir="${plugin.build.dir}/images">
    27                         <fileset dir="src/images" />
    28                 </copy>
    29                         <!-- copy configuration xml files -->
    30                 <copy todir="${plugin.build.dir}">
    31                         <fileset dir="src">
     26                <copy todir="${plugin.build.dir}/">
     27                        <fileset dir="resources">
    3228                                <include name="*.xml"/>
    33                 </fileset>
     29                                <include name="audio/*"/>
     30                  </fileset>
    3431                </copy>
    3532               
  • applications/editors/josm/plugins/surveyor/resources/surveyor.xml

    r3739 r3962  
    11<?xml version="1.0"?>
    2 <surveyor columns="4" width="0" height="0">
     2<surveyor columns="4" width="1300" height="0">
    33  <!-- icons can either be absolute paths or relative paths to the .josm directory -->
    44  <!-- action class: either fully qualified classnames or if not found,
    55       package at.dallermassl.josm.plugin.surveyor.action is assumed -->
    66  <button label="Tunnel Start" hotkey="T" icon="tunnel">
     7    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    78    <action class="SetWaypointAction" params="tunnel start"/>
    8     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    99    <!--action class="ConsolePrinterAction" params="tunnel start,tunnel"/-->
    1010    <!--action class="SystemExecuteAction" params="mplayer,-quiet,/usr/share/apps/klettres/de/alpha/x.ogg"/-->
    1111  </button>
    1212  <button label="Bridge" hotkey="B" type="toggle">
     13    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    1314    <action class="SetWaypointAction" params="bridge"/>
    14     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    1515  </button>
    1616  <button label="Village/City" hotkey="V" icon="place">
     17    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    1718    <action class="SetWaypointAction" params="village"/>
    18     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    1919    <!--
    2020    <action class="SetNodeAction" params=""/>
     
    2323  </button>
    2424  <button label="Parking" hotkey="P" icon="parking">
    25     <action class="SetNodeAction" params="amenity=parking"/>
     25    <!--action class="SetNodeAction" params="amenity=parking"/-->
     26    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    2627    <action class="SetWaypointAction" params="Parking"/>
    27     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    2828  </button>
    2929  <button label="One Way" hotkey="O" icon="noentry">
     30    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    3031    <action class="SetWaypointAction" params="oneway=yes"/>
    31     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    3232  </button>
    3333  <button label="Church" hotkey="C" icon="church">
     34    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    3435    <action class="SetNodeAction" params="amenity=place_of_worship,denomination=christian"/>
    3536    <action class="SetWaypointAction" params="Church"/>
    36     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    3737  </button>
    3838  <button label="Fuel Station" hotkey="F" icon="fuel">
    39     <action class="SetNodeAction" params="amenity=fuel"/>
     39    <!--action class="SetNodeAction" params="amenity=fuel"/-->
     40    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    4041    <action class="SetWaypointAction" params="Fuel"/>
    41     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    4242  </button>
    4343  <button label="Hotel" hotkey="H" icon="bed">
     44    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    4445    <action class="SetWaypointAction" params="Hotel"/>
    45     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    4646  </button>
    4747  <button label="Restaurant" hotkey="R" icon="restaurant">
     48    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    4849    <action class="SetNodeAction" params="amenity=restaurant"/>
    4950    <action class="SetWaypointAction" params="Restaurant"/>
    50     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
     51  </button>
     52  <button label="Shopping" hotkey="S" icon="shopping">
     53    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
     54    <action class="SetWaypointAction" params="Info"/>
     55  </button>
     56  <button label="WC" hotkey="W" icon="toilet">
     57    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
     58    <action class="SetWaypointAction" params="Info"/>
     59  </button>
     60  <button label="Camping" hotkey="Z" icon="caravan">
     61    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
     62    <action class="SetWaypointAction" params="Camping"/>
     63  </button>
     64  <button label="Info" hotkey="I">
     65    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
     66    <action class="SetWaypointAction" params="Info"/>
    5167  </button>
    5268  <button label="Exit" hotkey="E">
     69    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    5370    <action class="SetWaypointAction" params="Exit"/>
    54     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    5571  </button>
    5672  <button label="Motorway" hotkey="1">
     73    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    5774    <action class="SetWaypointAction" params="Motorway"/>
    58     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    5975  </button>
    6076  <button label="Primary" hotkey="2">
     77    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    6178    <action class="SetWaypointAction" params="Primary"/>
    62     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    6379  </button>
    6480  <button label="Secondary" hotkey="3">
     81    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    6582    <action class="SetWaypointAction" params="Secondary"/>
    66     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    6783  </button>
    6884  <button label="Unclassified" hotkey="4">
     85    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    6986    <action class="SetWaypointAction" params="Unclassified"/>
    70     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
    7187  </button>
    7288  <button label="Residential" hotkey="5">
     89    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
    7390    <action class="SetWaypointAction" params="Residential"/>
    74     <action class="PlayAudioAction" params="/usr/share/sounds/KDE_Window_Iconify.wav"/>
     91  </button>
     92  <button label="Test" hotkey="F12">
     93    <action class="PlayAudioAction" params="resource://audio/KDE_Window_Iconify.wav"/>
     94    <action class="SetWaypointAction" params="Test"/>
    7595  </button>
    7696</surveyor>
  • applications/editors/josm/plugins/surveyor/src/at/dallermassl/josm/plugin/surveyor/action/PlayAudioAction.java

    r3348 r3962  
    44package at.dallermassl.josm.plugin.surveyor.action;
    55
    6 import java.io.File;
     6import java.io.BufferedInputStream;
    77import java.io.IOException;
     8import java.io.InputStream;
    89import java.net.MalformedURLException;
    910
     
    1920
    2021import at.dallermassl.josm.plugin.surveyor.GpsActionEvent;
     22import at.dallermassl.josm.plugin.surveyor.util.ResourceLoader;
    2123
    2224/**
     
    2729 */
    2830public class PlayAudioAction extends AbstractSurveyorAction {
    29     private File audioFile = null;
     31    private String audioSource = null;
    3032
    3133    /* (non-Javadoc)
     
    3436    //@Override
    3537    public void actionPerformed(GpsActionEvent event) {
    36         try {
    37             if(audioFile == null) {
    38                 audioFile = new File(getParameters().get(0));
    39                 if(!audioFile.exists()) {
    40                     audioFile = new File(Main.pref.getPreferencesDir(), getParameters().get(0));
    41                     if(!audioFile.exists()) {
    42                         System.err.println("Audio file " + getParameters().get(0) + " not found!");
    43                         return;
     38        // run as a separate thread
     39        Main.worker.execute(new Runnable() {
     40            public void run() {
     41                try {
     42                    if(audioSource == null) {
     43                        audioSource = getParameters().get(0);
     44                        System.out.println("reading audio from " + audioSource);
    4445                    }
     46                    InputStream in = new BufferedInputStream(ResourceLoader.getInputStream(audioSource));
     47                    AudioInputStream stream = AudioSystem.getAudioInputStream(in);
     48
     49                    // From URL
     50//                  stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));
     51
     52                    // At present, ALAW and ULAW encodings must be converted
     53                    // to PCM_SIGNED before it can be played
     54                    AudioFormat format = stream.getFormat();
     55                    if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
     56                        format = new AudioFormat(
     57                            AudioFormat.Encoding.PCM_SIGNED,
     58                            format.getSampleRate(),
     59                            format.getSampleSizeInBits()*2,
     60                            format.getChannels(),
     61                            format.getFrameSize()*2,
     62                            format.getFrameRate(),
     63                            true);        // big endian
     64                        stream = AudioSystem.getAudioInputStream(format, stream);
     65                    }
     66
     67                    // Create the clip
     68                    DataLine.Info info = new DataLine.Info(
     69                        Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));
     70                    Clip clip = (Clip) AudioSystem.getLine(info);
     71
     72                    // This method does not return until the audio file is completely loaded
     73                    clip.open(stream);
     74
     75                    // Start playing
     76                    clip.start();
     77                } catch (MalformedURLException e) {
     78                    e.printStackTrace();
     79                } catch (IOException e) {
     80                    e.printStackTrace();
     81                } catch (LineUnavailableException e) {
     82                    e.printStackTrace();
     83                } catch (UnsupportedAudioFileException e) {
     84                    e.printStackTrace();
    4585                }
    4686            }
    47             // From file
    48             AudioInputStream stream = AudioSystem.getAudioInputStream(audioFile);
    49        
    50             // From URL
    51 //            stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));
    52        
    53             // At present, ALAW and ULAW encodings must be converted
    54             // to PCM_SIGNED before it can be played
    55             AudioFormat format = stream.getFormat();
    56             if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
    57                 format = new AudioFormat(
    58                         AudioFormat.Encoding.PCM_SIGNED,
    59                         format.getSampleRate(),
    60                         format.getSampleSizeInBits()*2,
    61                         format.getChannels(),
    62                         format.getFrameSize()*2,
    63                         format.getFrameRate(),
    64                         true);        // big endian
    65                 stream = AudioSystem.getAudioInputStream(format, stream);
    66             }
    67        
    68             // Create the clip
    69             DataLine.Info info = new DataLine.Info(
    70                 Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));
    71             Clip clip = (Clip) AudioSystem.getLine(info);
    72        
    73             // This method does not return until the audio file is completely loaded
    74             clip.open(stream);
    75        
    76             // Start playing
    77             clip.start();
    78         } catch (MalformedURLException e) {
    79             e.printStackTrace();
    80         } catch (IOException e) {
    81             e.printStackTrace();
    82         } catch (LineUnavailableException e) {
    83             e.printStackTrace();
    84         } catch (UnsupportedAudioFileException e) {
    85             e.printStackTrace();
    86         }
     87           
     88        });
    8789       
    8890    }
Note: See TracChangeset for help on using the changeset viewer.