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

Last change on this file since 6084 was 6084, checked in by bastiK, 11 years ago

see #8902 - add missing @Override annotations (patch by shinigami)

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