source: josm/trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/AudioMarker.java@ 9078

Last change on this file since 9078 was 9078, checked in by Don-vip, 8 years ago

sonar - Immutable Field

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.layer.markerlayer;
3
4import java.awt.event.ActionEvent;
5import java.net.URL;
6import java.util.Collections;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.data.coor.LatLon;
10import org.openstreetmap.josm.data.gpx.GpxConstants;
11import org.openstreetmap.josm.data.gpx.GpxLink;
12import org.openstreetmap.josm.data.gpx.WayPoint;
13import org.openstreetmap.josm.tools.AudioPlayer;
14import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
15
16/**
17 * Marker class with audio playback capability.
18 *
19 * @author Frederik Ramm
20 *
21 */
22public class AudioMarker extends ButtonMarker {
23
24 private final URL audioUrl;
25 private static volatile AudioMarker recentlyPlayedMarker;
26 public double syncOffset;
27 public boolean timeFromAudio; // as opposed to from the GPX track
28
29 public AudioMarker(LatLon ll, TemplateEngineDataProvider dataProvider, URL audioUrl, MarkerLayer parentLayer, double time, double offset) {
30 super(ll, dataProvider, "speech", parentLayer, time, offset);
31 this.audioUrl = audioUrl;
32 this.syncOffset = 0.0;
33 this.timeFromAudio = false;
34 }
35
36 @Override
37 public void actionPerformed(ActionEvent ev) {
38 play();
39 }
40
41 public static AudioMarker recentlyPlayedMarker() {
42 return recentlyPlayedMarker;
43 }
44
45 public URL url() {
46 return audioUrl;
47 }
48
49 /**
50 * Starts playing the audio associated with the marker offset by the given amount
51 * @param after : seconds after marker where playing should start
52 */
53 public void play(double after) {
54 try {
55 // first enable tracing the audio along the track
56 Main.map.mapView.playHeadMarker.animate();
57
58 AudioPlayer.play(audioUrl, offset + syncOffset + after);
59 recentlyPlayedMarker = this;
60 } catch (Exception e) {
61 AudioPlayer.audioMalfunction(e);
62 }
63 }
64
65 /**
66 * Starts playing the audio associated with the marker: used in response to pressing
67 * the marker as well as indirectly
68 *
69 */
70 public void play() {
71 play(0.0);
72 }
73
74 public void adjustOffset(double adjustment) {
75 syncOffset = adjustment; // added to offset may turn out negative, but that's ok
76 }
77
78 public double syncOffset() {
79 return syncOffset;
80 }
81
82 @Override
83 protected TemplateEntryProperty getTextTemplate() {
84 return TemplateEntryProperty.forAudioMarker(parentLayer.getName());
85 }
86
87 @Override
88 public WayPoint convertToWayPoint() {
89 WayPoint wpt = super.convertToWayPoint();
90 GpxLink link = new GpxLink(audioUrl.toString());
91 link.type = "audio";
92 wpt.put(GpxConstants.META_LINKS, Collections.singleton(link));
93 wpt.addExtension("offset", Double.toString(offset));
94 wpt.addExtension("sync-offset", Double.toString(syncOffset));
95 return wpt;
96 }
97}
Note: See TracBrowser for help on using the repository browser.