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

Last change on this file since 11124 was 8510, checked in by Don-vip, 9 years ago

checkstyle: enable relevant whitespace checks and fix them

  • Property svn:eol-style set to native
File size: 2.2 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;
16import org.openstreetmap.josm.tools.Utils;
17
18/**
19 * If not playing, play the sound track from the first Audio Marker, or from the point at which it was paused.<br>
20 * If playing, pause the sound.<br>
21 * If fast forwarding or slow forwarding, resume normal speed.
22 * @since 547
23 */
24public class AudioPlayPauseAction extends JosmAction {
25
26 /**
27 * Constructs a new {@code AudioPlayPauseAction}.
28 */
29 public AudioPlayPauseAction() {
30 super(trc("audio", "Play/Pause"), "audio-playpause", tr("Play/pause audio."),
31 Shortcut.registerShortcut("audio:pause", tr("Audio: {0}", trc("audio", "Play/Pause")), KeyEvent.VK_PERIOD, Shortcut.DIRECT), true);
32 }
33
34 @Override
35 public void actionPerformed(ActionEvent e) {
36 URL url = AudioPlayer.url();
37 try {
38 if (AudioPlayer.paused() && url != null) {
39 AudioPlayer.play(url);
40 } else if (AudioPlayer.playing()) {
41 if (!Utils.equalsEpsilon(AudioPlayer.speed(), 1.0))
42 AudioPlayer.play(url, AudioPlayer.position());
43 else
44 AudioPlayer.pause();
45 } else {
46 // play the last-played marker again, if there is one
47 AudioMarker lastPlayed = AudioMarker.recentlyPlayedMarker();
48 if (lastPlayed != null) {
49 lastPlayed.play();
50 } else {
51 // If no marker was played recently, play the first one
52 MarkerLayer.playAudio();
53 }
54 }
55 } catch (Exception ex) {
56 AudioPlayer.audioMalfunction(ex);
57 }
58 }
59}
Note: See TracBrowser for help on using the repository browser.