Ignore:
Timestamp:
2017-06-07T21:41:26+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #2089 - Add support for MP3, AIFF and AAC audio codecs (.mp3, .aac, .aif, .aiff files) if Java FX is on the classpath (i.e. Windows, macOS, nearly all major Linux distributions). The classes are not public on purpose, as the whole system will have to be simplified when all Linux distributions propose Java FX and so we can get rid of old Java Sound implementation.

Location:
trunk/src/org/openstreetmap/josm/gui/layer
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r12326 r12328  
    4141    private final transient GpxLayer layer;
    4242
    43     static final class AudioFileFilter extends FileFilter {
     43    /**
     44     * Audio file filter.
     45     * @since 12328
     46     */
     47    public static final class AudioFileFilter extends FileFilter {
    4448        @Override
    4549        public boolean accept(File f) {
    46             return f.isDirectory() || Utils.hasExtension(f, "wav");
     50            return f.isDirectory() || Utils.hasExtension(f, "wav", "mp3", "aac", "aif", "aiff");
    4751        }
    4852
    4953        @Override
    5054        public String getDescription() {
    51             return tr("Wave Audio files (*.wav)");
     55            return tr("Audio files (*.wav, *.mp3, *.aac, *.aif, *.aiff)");
    5256        }
    5357    }
     
    119123     * which the given audio file is associated with. Markers are derived from the following (a)
    120124     * explict waypoints in the GPX layer, or (b) named trackpoints in the GPX layer, or (d)
    121      * timestamp on the wav file (e) (in future) voice recognised markers in the sound recording (f)
     125     * timestamp on the audio file (e) (in future) voice recognised markers in the sound recording (f)
    122126     * a single marker at the beginning of the track
    123      * @param wavFile the file to be associated with the markers in the new marker layer
     127     * @param audioFile the file to be associated with the markers in the new marker layer
    124128     * @param ml marker layer
    125129     * @param firstStartTime first start time in milliseconds, used for (d)
    126130     * @param markers keeps track of warning messages to avoid repeated warnings
    127131     */
    128     private void importAudio(File wavFile, MarkerLayer ml, double firstStartTime, Markers markers) {
    129         URL url = Utils.fileToURL(wavFile);
     132    private void importAudio(File audioFile, MarkerLayer ml, double firstStartTime, Markers markers) {
     133        URL url = Utils.fileToURL(audioFile);
    130134        boolean hasTracks = layer.data.tracks != null && !layer.data.tracks.isEmpty();
    131135        boolean hasWaypoints = layer.data.waypoints != null && !layer.data.waypoints.isEmpty();
     
    212216        // (d) use timestamp of file as location on track
    213217        if (hasTracks && Main.pref.getBoolean("marker.audiofromwavtimestamps", false)) {
    214             double lastModified = wavFile.lastModified() / 1000.0; // lastModified is in
    215             // milliseconds
    216             double duration = AudioUtil.getCalibratedDuration(wavFile);
     218            double lastModified = audioFile.lastModified() / 1000.0; // lastModified is in milliseconds
     219            double duration = AudioUtil.getCalibratedDuration(audioFile);
    217220            double startTime = lastModified - duration;
    218221            startTime = firstStartTime + (startTime - firstStartTime)
     
    242245                        (startTime - w1.time) / (w2.time - w1.time)));
    243246                wayPointFromTimeStamp.time = startTime;
    244                 String name = wavFile.getName();
     247                String name = audioFile.getName();
    245248                int dot = name.lastIndexOf('.');
    246249                if (dot > 0) {
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/AudioMarker.java

    r12326 r12328  
    1313import org.openstreetmap.josm.data.gpx.WayPoint;
    1414import org.openstreetmap.josm.io.audio.AudioPlayer;
     15import org.openstreetmap.josm.io.audio.AudioUtil;
    1516import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
    1617
     
    6061            recentlyPlayedMarker = this;
    6162        } catch (IOException | InterruptedException e) {
    62             AudioPlayer.audioMalfunction(e);
     63            AudioUtil.audioMalfunction(e);
    6364        }
    6465    }
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/DefaultMarkerProducers.java

    r11892 r12328  
    4444        if (url == null) {
    4545            return Collections.singleton(marker);
    46         } else if (urlStr.endsWith(".wav")) {
     46        } else if (Utils.hasExtension(urlStr, "wav", "mp3", "aac", "aif", "aiff")) {
    4747            final AudioMarker audioMarker = new AudioMarker(wpt.getCoor(), wpt, url, parentLayer, time, offset);
    4848            Extensions exts = (Extensions) wpt.get(GpxConstants.META_EXTENSIONS);
     
    5555            }
    5656            return Arrays.asList(marker, audioMarker);
    57         } else if (urlStr.endsWith(".png") || urlStr.endsWith(".jpg") || urlStr.endsWith(".jpeg")
    58                 || urlStr.endsWith(".gif")) {
     57        } else if (Utils.hasExtension(urlStr, "png", "jpg", "jpeg", "gif")) {
    5958            return Arrays.asList(marker, new ImageMarker(wpt.getCoor(), url, parentLayer, time, offset));
    6059        } else {
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r11892 r12328  
    5353 *
    5454 * By default, one the list contains one default "Maker" implementation that
    55  * will create AudioMarkers for .wav files, ImageMarkers for .png/.jpg/.jpeg
     55 * will create AudioMarkers for supported audio files, ImageMarkers for supported image
    5656 * files, and WebMarkers for everything else. (The creation of a WebMarker will
    5757 * fail if there's no valid URL in the <link> tag, so it might still make sense
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/PlayHeadMarker.java

    r12326 r12328  
    2525import org.openstreetmap.josm.gui.layer.GpxLayer;
    2626import org.openstreetmap.josm.io.audio.AudioPlayer;
     27import org.openstreetmap.josm.io.audio.AudioUtil;
    2728
    2829/**
     
    100101                AudioPlayer.pause();
    101102            } catch (IOException | InterruptedException ex) {
    102                 AudioPlayer.audioMalfunction(ex);
     103                AudioUtil.audioMalfunction(ex);
    103104            }
    104105        }
     
    114115                AudioPlayer.pause();
    115116            } catch (IOException | InterruptedException ex) {
    116                 AudioPlayer.audioMalfunction(ex);
     117                AudioUtil.audioMalfunction(ex);
    117118            }
    118119        }
Note: See TracChangeset for help on using the changeset viewer.