source: josm/trunk/src/org/openstreetmap/josm/actions/audio/AudioFastSlowAction.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: 1.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.audio;
3
4import java.awt.event.ActionEvent;
5import java.io.IOException;
6
7import org.openstreetmap.josm.Main;
8import org.openstreetmap.josm.actions.JosmAction;
9import org.openstreetmap.josm.io.audio.AudioPlayer;
10import org.openstreetmap.josm.io.audio.AudioUtil;
11import org.openstreetmap.josm.tools.Shortcut;
12
13/**
14 * Abstract superclass of {@link AudioFasterAction} and {@link AudioSlowerAction}.
15 * @since 563
16 */
17public abstract class AudioFastSlowAction extends JosmAction {
18
19 private double multiplier;
20
21 /**
22 * Constructs a new {@code AudioFastSlowAction}.
23 *
24 * @param name the action's text as displayed on the menu (if it is added to a menu)
25 * @param iconName the filename of the icon to use
26 * @param tooltip a longer description of the action that will be displayed in the tooltip.
27 * @param shortcut a ready-created shortcut object.
28 * @param fast {@code true} to increase speed (faster audio), {@code false} to decrease it (slower audio).
29 */
30 public AudioFastSlowAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean fast) {
31 super(name, iconName, tooltip, shortcut, true);
32 multiplier = Main.pref.getDouble("audio.fastfwdmultiplier", 1.3);
33 if (!fast)
34 multiplier = 1.0 / multiplier;
35 }
36
37 @Override
38 public void actionPerformed(ActionEvent e) {
39 double speed = AudioPlayer.speed();
40 if (speed * multiplier <= 0.1)
41 return;
42 try {
43 if (AudioPlayer.playing() || AudioPlayer.paused())
44 AudioPlayer.play(AudioPlayer.url(), AudioPlayer.position(), speed * multiplier);
45 } catch (IOException | InterruptedException ex) {
46 AudioUtil.audioMalfunction(ex);
47 }
48 }
49}
Note: See TracBrowser for help on using the repository browser.