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

Last change on this file since 7310 was 6830, checked in by Don-vip, 10 years ago

javadoc fixes for jdk8 compatibility

  • 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 URL audioUrl;
25 private static AudioMarker recentlyPlayedMarker = null;
26 public double syncOffset;
27 public boolean timeFromAudio = false; // 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.png", parentLayer, time, offset);
31 this.audioUrl = audioUrl;
32 this.syncOffset = 0.0;
33 this.timeFromAudio = false;
34 }
35
36 @Override public void actionPerformed(ActionEvent ev) {
37 play();
38 }
39
40 public static AudioMarker recentlyPlayedMarker() {
41 return recentlyPlayedMarker;
42 }
43
44 public URL url() {
45 return audioUrl;
46 }
47
48 /**
49 * Starts playing the audio associated with the marker offset by the given amount
50 * @param after : seconds after marker where playing should start
51 */
52 public void play(double after) {
53 try {
54 // first enable tracing the audio along the track
55 Main.map.mapView.playHeadMarker.animate();
56
57 AudioPlayer.play(audioUrl, offset + syncOffset + after);
58 recentlyPlayedMarker = this;
59 } catch (Exception e) {
60 AudioPlayer.audioMalfunction(e);
61 }
62 }
63
64 /**
65 * Starts playing the audio associated with the marker: used in response to pressing
66 * the marker as well as indirectly
67 *
68 */
69 public void play() { play(0.0); }
70
71 public void adjustOffset(double adjustment) {
72 syncOffset = adjustment; // added to offset may turn out negative, but that's ok
73 }
74
75 public double syncOffset() {
76 return syncOffset;
77 }
78
79 @Override
80 protected TemplateEntryProperty getTextTemplate() {
81 return TemplateEntryProperty.forAudioMarker(parentLayer.getName());
82 }
83
84 @Override
85 public WayPoint convertToWayPoint() {
86 WayPoint wpt = super.convertToWayPoint();
87 GpxLink link = new GpxLink(audioUrl.toString());
88 link.type = "audio";
89 wpt.attr.put(GpxConstants.META_LINKS, Collections.singleton(link));
90 wpt.addExtension("offset", Double.toString(offset));
91 wpt.addExtension("sync-offset", Double.toString(syncOffset));
92 return wpt;
93 }
94}
Note: See TracBrowser for help on using the repository browser.