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

Last change on this file since 1677 was 1677, checked in by stoecker, 15 years ago

remove all these ugly tab stops introduced in the last half year

  • Property svn:eol-style set to native
File size: 3.0 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;
10
11/**
12 * Marker class with audio playback capability.
13 *
14 * @author Frederik Ramm <frederik@remote.org>
15 *
16 */
17public class AudioMarker extends ButtonMarker {
18
19 private URL audioUrl;
20 private static AudioMarker recentlyPlayedMarker = null;
21 public double syncOffset;
22 public boolean timeFromAudio = false; // as opposed to from the GPX track
23
24 /**
25 * Verifies the parameter whether a new AudioMarker can be created and return
26 * one or return <code>null</code>.
27 */
28 public static AudioMarker create(LatLon ll, String text, String url, MarkerLayer parentLayer, double time, double offset) {
29 try {
30 return new AudioMarker(ll, text, new URL(url), parentLayer, time, offset);
31 } catch (Exception ex) {
32 return null;
33 }
34 }
35
36 private AudioMarker(LatLon ll, String text, URL audioUrl, MarkerLayer parentLayer, double time, double offset) {
37 super(ll, text, "speech.png", parentLayer, time, offset);
38 this.audioUrl = audioUrl;
39 this.syncOffset = 0.0;
40 this.timeFromAudio = false;
41 }
42
43 @Override public void actionPerformed(ActionEvent ev) {
44 play();
45 }
46
47 public static AudioMarker recentlyPlayedMarker() {
48 return recentlyPlayedMarker;
49 }
50
51 public URL url() {
52 return audioUrl;
53 }
54
55 /**
56 * Starts playing the audio associated with the marker offset by the given amount
57 * @param after : seconds after marker where playing should start
58 */
59 public void play(double after) {
60 try {
61 // first enable tracing the audio along the track
62 Main.map.mapView.playHeadMarker.animate();
63
64 AudioPlayer.play(audioUrl, offset + syncOffset + after);
65 recentlyPlayedMarker = this;
66 } catch (Exception e) {
67 AudioPlayer.audioMalfunction(e);
68 }
69 }
70
71 /**
72 * Starts playing the audio associated with the marker: used in response to pressing
73 * the marker as well as indirectly
74 *
75 */
76 public void play() { play(0.0); }
77
78 public void adjustOffset(double adjustment) {
79 syncOffset = adjustment; // added to offset may turn out negative, but that's ok
80 }
81
82 public double syncOffset() {
83 return syncOffset;
84 }
85
86 public static String inventName (double offset) {
87 int wholeSeconds = (int)(offset + 0.5);
88 if (wholeSeconds < 60)
89 return Integer.toString(wholeSeconds);
90 else if (wholeSeconds < 3600)
91 return String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60);
92 else
93 return String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60);
94 }
95}
Note: See TracBrowser for help on using the repository browser.