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

Last change on this file since 572 was 572, checked in by david, 16 years ago

Reorganise audio interface in light of recent usability comments

File size: 3.1 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 offset by the given amount
71 * @param after : seconds after marker where playing should start
72 */
73 public void play(double after) {
74 try {
75 // first enable tracing the audio along the track
76 Main.map.mapView.playHeadMarker.animate();
77
78 AudioPlayer.play(audioUrl, offset + syncOffset + after);
79 recentlyPlayedMarker = this;
80 } catch (Exception e) {
81 AudioPlayer.audioMalfunction(e);
82 }
83 }
84
85 /**
86 * Starts playing the audio associated with the marker: used in response to pressing
87 * the marker as well as indirectly
88 *
89 */
90 public void play() { play(0.0); }
91
92 public void adjustOffset(double adjustment) {
93 syncOffset = adjustment; // added to offset may turn out negative, but that's ok
94 }
95
96 public double syncOffset() {
97 return syncOffset;
98 }
99
100 public static String inventName (double offset) {
101 int wholeSeconds = (int)(offset + 0.5);
102 if (wholeSeconds < 60)
103 return Integer.toString(wholeSeconds);
104 else if (wholeSeconds < 3600)
105 return String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60);
106 else
107 return String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60);
108 }
109}
Note: See TracBrowser for help on using the repository browser.