source: josm/trunk/src/org/openstreetmap/josm/actions/audio/AudioFastSlowAction.java@ 12565

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

fix #15110 - Disable audio actions when no audio is present (patch by bafonins, modified)

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