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

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

fix #2089 - Add support for MP3, AIFF and AAC audio codecs (.mp3, .aac, .aif, .aiff files) if Java FX is on the classpath (i.e. Windows, macOS, nearly all major Linux distributions). The classes are not public on purpose, as the whole system will have to be simplified when all Linux distributions propose Java FX and so we can get rid of old Java Sound implementation.

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