Package org.openstreetmap.josm.actions.audio

Source Code of org.openstreetmap.josm.actions.audio.AudioPlayPauseAction

// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.actions.audio;

import static org.openstreetmap.josm.tools.I18n.tr;
import static org.openstreetmap.josm.tools.I18n.trc;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.net.URL;

import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker;
import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
import org.openstreetmap.josm.tools.AudioPlayer;
import org.openstreetmap.josm.tools.Shortcut;

/**
* If not playing, play the sound track from the first Audio Marker, or from the point at which it was paused.<br>
* If playing, pause the sound.<br>
* If fast forwarding or slow forwarding, resume normal speed.
* @since 547
*/
public class AudioPlayPauseAction extends JosmAction {

    /**
     * Constructs a new {@code AudioPlayPauseAction}.
     */
    public AudioPlayPauseAction() {
        super(trc("audio", "Play/Pause"), "audio-playpause", tr("Play/pause audio."),
        Shortcut.registerShortcut("audio:pause", tr("Audio: {0}", trc("audio", "Play/Pause")), KeyEvent.VK_PERIOD, Shortcut.DIRECT), true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        URL url = AudioPlayer.url();
        try {
            if (AudioPlayer.paused() && url != null) {
                AudioPlayer.play(url);
            } else if (AudioPlayer.playing()){
                if (AudioPlayer.speed() != 1.0)
                    AudioPlayer.play(url, AudioPlayer.position());
                else
                    AudioPlayer.pause();
            } else {
                // play the last-played marker again, if there is one
                AudioMarker lastPlayed = AudioMarker.recentlyPlayedMarker();
                if (lastPlayed != null) {
                    lastPlayed.play();
                } else {
                    // If no marker was played recently, play the first one
                    MarkerLayer.playAudio();
                }
            }
        } catch (Exception ex) {
            AudioPlayer.audioMalfunction(ex);
        }
    }
}
TOP

Related Classes of org.openstreetmap.josm.actions.audio.AudioPlayPauseAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.