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

Last change on this file since 5945 was 5945, checked in by stoecker, 11 years ago

fix #8522 - remember and play last played audio marker for start/stop

  • 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 public void actionPerformed(ActionEvent e) {
33 URL url = AudioPlayer.url();
34 try {
35 if (AudioPlayer.paused() && url != null) {
36 AudioPlayer.play(url);
37 } else if (AudioPlayer.playing()){
38 if (AudioPlayer.speed() != 1.0)
39 AudioPlayer.play(url, AudioPlayer.position());
40 else
41 AudioPlayer.pause();
42 } else {
43 // play the last-played marker again, if there is one
44 AudioMarker lastPlayed = AudioMarker.recentlyPlayedMarker();
45 if (lastPlayed != null) {
46 lastPlayed.play();
47 } else {
48 // If no marker was played recently, play the first one
49 MarkerLayer.playAudio();
50 }
51 }
52 } catch (Exception ex) {
53 AudioPlayer.audioMalfunction(ex);
54 }
55 }
56}
Note: See TracBrowser for help on using the repository browser.