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

Last change on this file since 4282 was 4282, checked in by jttt, 13 years ago

Allow to specify custom pattern for marker text labels

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