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

Last change on this file since 554 was 554, checked in by david, 17 years ago

new "Add Audio Marker At Play Head" facility; and tidy up Audio Preferences; default for displaying audio trace now true.

File size: 2.9 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.gui.layer.markerlayer;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Graphics;
7import java.awt.Point;
8import java.awt.Rectangle;
9import java.awt.event.ActionEvent;
10import java.awt.event.ActionListener;
11import java.io.IOException;
12import java.net.URL;
13
14import javax.swing.Icon;
15import javax.swing.JOptionPane;
16import javax.swing.Timer;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.data.coor.LatLon;
20import org.openstreetmap.josm.tools.AudioPlayer;
21import org.openstreetmap.josm.data.gpx.WayPoint;
22import org.openstreetmap.josm.data.coor.EastNorth;
23import org.openstreetmap.josm.gui.MapView;
24
25import org.openstreetmap.josm.tools.ImageProvider;
26
27/**
28 * Marker class with audio playback capability.
29 *
30 * @author Frederik Ramm <frederik@remote.org>
31 *
32 */
33public class AudioMarker extends ButtonMarker {
34
35 private URL audioUrl;
36 private static AudioMarker recentlyPlayedMarker = null;
37 public double syncOffset;
38
39 /**
40 * Verifies the parameter whether a new AudioMarker can be created and return
41 * one or return <code>null</code>.
42 */
43 public static AudioMarker create(LatLon ll, String text, String url, MarkerLayer parentLayer, double time, double offset) {
44 try {
45 return new AudioMarker(ll, text, new URL(url), parentLayer, time, offset);
46 } catch (Exception ex) {
47 return null;
48 }
49 }
50
51 private AudioMarker(LatLon ll, String text, URL audioUrl, MarkerLayer parentLayer, double time, double offset) {
52 super(ll, text, "speech.png", parentLayer, time, offset);
53 this.audioUrl = audioUrl;
54 this.syncOffset = 0.0;
55 }
56
57 @Override public void actionPerformed(ActionEvent ev) {
58 play();
59 }
60
61 public static AudioMarker recentlyPlayedMarker() {
62 return recentlyPlayedMarker;
63 }
64
65 public URL url() {
66 return audioUrl;
67 }
68
69 /**
70 * Starts playing the audio associated with the marker: used in response to pressing
71 * the marker as well as indirectly
72 *
73 */
74 public void play() {
75 try {
76 // first enable tracing the audio along the track
77 if (Main.pref.getBoolean("marker.traceaudio", true) && parentLayer != null) {
78 parentLayer.traceAudio();
79 }
80
81 AudioPlayer.play(audioUrl, offset + syncOffset);
82 recentlyPlayedMarker = this;
83 } catch (Exception e) {
84 AudioPlayer.audioMalfunction(e);
85 }
86 }
87
88 public void adjustOffset(double adjustment) {
89 syncOffset = adjustment; // added to offset may turn out negative, but that's ok
90 }
91
92 public double syncOffset() {
93 return syncOffset;
94 }
95
96 public static String inventName (double offset) {
97 int wholeSeconds = (int)(offset + 0.5);
98 if (wholeSeconds < 60)
99 return Integer.toString(wholeSeconds);
100 else if (wholeSeconds < 3600)
101 return String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60);
102 else
103 return String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60);
104 }
105}
Note: See TracBrowser for help on using the repository browser.