Class AudioPlayer

java.lang.Object
java.lang.Thread
org.openstreetmap.josm.io.audio.AudioPlayer
All Implemented Interfaces:
Runnable, AudioListener

public final class AudioPlayer extends Thread implements AudioListener
Creates and controls a separate audio player thread.
Since:
12326 (move to new package), 547
  • Field Details

  • Constructor Details

  • Method Details

    • play

      public static void play(URL url) throws InterruptedException, IOException
      Plays a WAV audio file from the beginning. See also the variant which doesn't start at the beginning of the stream
      Parameters:
      url - The resource to play, which must be a WAV file or stream
      Throws:
      InterruptedException - thread interrupted
      IOException - audio fault exception, e.g. can't open stream, unhandleable audio format
    • play

      public static void play(URL url, double seconds) throws InterruptedException, IOException
      Plays a WAV audio file from a specified position.
      Parameters:
      url - The resource to play, which must be a WAV file or stream
      seconds - The number of seconds into the audio to start playing
      Throws:
      InterruptedException - thread interrupted
      IOException - audio fault exception, e.g. can't open stream, unhandleable audio format
    • play

      public static void play(URL url, double seconds, double speed) throws InterruptedException, IOException
      Plays a WAV audio file from a specified position at variable speed.
      Parameters:
      url - The resource to play, which must be a WAV file or stream
      seconds - The number of seconds into the audio to start playing
      speed - Rate at which audio plays (1.0 = real time, > 1 is faster)
      Throws:
      InterruptedException - thread interrupted
      IOException - audio fault exception, e.g. can't open stream, unhandleable audio format
    • pause

      public static void pause() throws InterruptedException, IOException
      Pauses the currently playing audio stream. Does nothing if nothing playing.
      Throws:
      InterruptedException - thread interrupted
      IOException - audio fault exception, e.g. can't open stream, unhandleable audio format
    • url

      public static URL url()
      To get the Url of the playing or recently played audio.
      Returns:
      url - could be null
    • paused

      public static boolean paused()
      Whether or not we are paused.
      Returns:
      boolean whether or not paused
    • playing

      public static boolean playing()
      Whether or not we are playing.
      Returns:
      boolean whether or not playing
    • position

      public static double position()
      How far we are through playing, in seconds.
      Returns:
      double seconds
    • speed

      public static double speed()
      Speed at which we will play.
      Returns:
      double, speed multiplier
    • getInstance

      private static AudioPlayer getInstance()
      Returns the singleton object, and if this is the first time, creates it along with the thread to support audio
      Returns:
      the unique instance
    • reset

      public static void reset()
      Resets the audio player.
    • run

      public void run()
      Starts the thread to actually play the audio, per Thread interface Not to be used as public, though Thread interface doesn't allow it to be made private
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • playing

      public void playing(URL playingUrl)
      Description copied from interface: AudioListener
      Called when a new URL is being played.
      Specified by:
      playing in interface AudioListener
      Parameters:
      playingUrl - new URL being played
    • getSoundPlayerClass

      public static Class<? extends SoundPlayer> getSoundPlayerClass()
      Returns the custom sound player class, if any.
      Returns:
      the custom sound player class, or null
      Since:
      14183
    • setSoundPlayerClass

      public static void setSoundPlayerClass(Class<? extends SoundPlayer> playerClass)
      Sets the custom sound player class to override default core player. Must be called before the first audio method invocation.
      Parameters:
      playerClass - custom sound player class to override default core player
      Since:
      14183