source: josm/trunk/src/org/openstreetmap/josm/actions/audio/AudioPlayPauseAction.java@ 6706

Last change on this file since 6706 was 6380, checked in by Don-vip, 10 years ago

update license/copyright information

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.audio;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trc;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9import java.net.URL;
10
11import org.openstreetmap.josm.actions.JosmAction;
12import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker;
13import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
14import org.openstreetmap.josm.tools.AudioPlayer;
15import 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 */
23public 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}
Note: See TracBrowser for help on using the repository browser.