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

Last change on this file since 11746 was 11746, checked in by Don-vip, 7 years ago

PMD - Strict Exceptions

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