1 | // License: GPL. Copyright 2008 by David Earl and others
|
---|
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 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.net.URL;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
11 | import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
|
---|
12 | import org.openstreetmap.josm.tools.AudioPlayer;
|
---|
13 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
14 |
|
---|
15 | public class AudioPlayPauseAction extends JosmAction {
|
---|
16 |
|
---|
17 | public AudioPlayPauseAction() {
|
---|
18 | super(trc("audio", "Play/Pause"), "audio-playpause", tr("Play/pause audio."),
|
---|
19 | Shortcut.registerShortcut("audio:pause", tr("Audio: {0}", trc("audio", "Play/Pause")), KeyEvent.VK_PERIOD, Shortcut.DIRECT), true);
|
---|
20 | }
|
---|
21 |
|
---|
22 | public void actionPerformed(ActionEvent e) {
|
---|
23 | URL url = AudioPlayer.url();
|
---|
24 | try {
|
---|
25 | if (AudioPlayer.paused() && url != null) {
|
---|
26 | AudioPlayer.play(url);
|
---|
27 | } else if (AudioPlayer.playing()){
|
---|
28 | if (AudioPlayer.speed() != 1.0)
|
---|
29 | AudioPlayer.play(url, AudioPlayer.position());
|
---|
30 | else
|
---|
31 | AudioPlayer.pause();
|
---|
32 | } else {
|
---|
33 | // find first audio marker to play
|
---|
34 | MarkerLayer.playAudio();
|
---|
35 | }
|
---|
36 | } catch (Exception ex) {
|
---|
37 | AudioPlayer.audioMalfunction(ex);
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|