1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.audio;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.trc;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.net.URL;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
12 | import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker;
|
---|
13 | import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
|
---|
14 | import org.openstreetmap.josm.tools.AudioPlayer;
|
---|
15 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * If not playing, play the sound track from the first Audio Marker, or from the point at which it was paused.<br>
|
---|
19 | * If playing, pause the sound.<br>
|
---|
20 | * If fast forwarding or slow forwarding, resume normal speed.
|
---|
21 | * @since 547
|
---|
22 | */
|
---|
23 | public class AudioPlayPauseAction extends JosmAction {
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new {@code AudioPlayPauseAction}.
|
---|
27 | */
|
---|
28 | public AudioPlayPauseAction() {
|
---|
29 | super(trc("audio", "Play/Pause"), "audio-playpause", tr("Play/pause audio."),
|
---|
30 | Shortcut.registerShortcut("audio:pause", tr("Audio: {0}", trc("audio", "Play/Pause")), KeyEvent.VK_PERIOD, Shortcut.DIRECT), true);
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public void actionPerformed(ActionEvent e) {
|
---|
35 | URL url = AudioPlayer.url();
|
---|
36 | try {
|
---|
37 | if (AudioPlayer.paused() && url != null) {
|
---|
38 | AudioPlayer.play(url);
|
---|
39 | } else if (AudioPlayer.playing()){
|
---|
40 | if (AudioPlayer.speed() != 1.0)
|
---|
41 | AudioPlayer.play(url, AudioPlayer.position());
|
---|
42 | else
|
---|
43 | AudioPlayer.pause();
|
---|
44 | } else {
|
---|
45 | // play the last-played marker again, if there is one
|
---|
46 | AudioMarker lastPlayed = AudioMarker.recentlyPlayedMarker();
|
---|
47 | if (lastPlayed != null) {
|
---|
48 | lastPlayed.play();
|
---|
49 | } else {
|
---|
50 | // If no marker was played recently, play the first one
|
---|
51 | MarkerLayer.playAudio();
|
---|
52 | }
|
---|
53 | }
|
---|
54 | } catch (Exception ex) {
|
---|
55 | AudioPlayer.audioMalfunction(ex);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|