Class MP3Player

java.lang.Object
java.lang.Thread
org.sm.smtools.util.MP3Player
All Implemented Interfaces:
java.lang.Runnable

public final class MP3Player
extends java.lang.Thread
The MP3Player class is a helper class for the JLayer framework.

When playing a sound file or stream, the application's execution can be blocked, or it the playing can be delegated to a non-blocking thread.

Note that a valid I18NL10N database must be available!

Note that this class cannot be subclassed!

Version:
06/08/2019
Author:
Sven Maerivoet
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  MP3Player.EPlaying
    Useful constants to specify whether or not the application's execution is blocked while playing a sound.

    Nested classes/interfaces inherited from class java.lang.Thread

    java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
  • Field Summary

    Fields inherited from class java.lang.Thread

    MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
  • Constructor Summary

    Constructors
    Constructor Description
    MP3Player​(java.io.InputStream soundInputStream)
    Constructs an MP3Player object based on a specified InputStream.
    MP3Player​(java.lang.String soundFilename)
    Constructs an MP3Player object based on a specified filename.
  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes the player.
    static void disableSystemSounds()
    Disables the playing of system sounds.
    static void enableSystemSounds()
    Enables the playing of system sounds.
    void play​(MP3Player.EPlaying playing)
    Starts playing a loaded sound file or stream.
    static void playSystemSound​(java.lang.String soundFilename)
    Plays a specified system sound.
    static void playSystemSound​(java.lang.String soundFilename, MP3Player.EPlaying playing)
    Plays a specified system sound.
    void run()
    The Thread's run() method.
    static boolean systemSoundsEnabled()
    Returns whether or not system sounds are enabled.

    Methods inherited from class java.lang.Thread

    activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, toString, yield

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • MP3Player

      public MP3Player​(java.lang.String soundFilename) throws java.io.FileNotFoundException, SoundPlayingException
      Constructs an MP3Player object based on a specified filename.
      Parameters:
      soundFilename - the name of the file containing the MP3 sound
      Throws:
      java.io.FileNotFoundException - if the specified file could not be found or loaded
      SoundPlayingException - if something went wrong during playing
    • MP3Player

      public MP3Player​(java.io.InputStream soundInputStream) throws SoundPlayingException
      Constructs an MP3Player object based on a specified InputStream.
      Parameters:
      soundInputStream - the InputStream containing the MP3 sound
      Throws:
      SoundPlayingException - if something went wrong during playing
  • Method Details

    • close

      public void close()
      Closes the player.
    • run

      public void run()
      The Thread's run() method.
      Specified by:
      run in interface java.lang.Runnable
      Overrides:
      run in class java.lang.Thread
    • play

      public void play​(MP3Player.EPlaying playing) throws SoundPlayingException
      Starts playing a loaded sound file or stream.
      Parameters:
      playing - specifies whether or not the application's execution should be blocked when playing the sound
      Throws:
      SoundPlayingException - when an exception occurs during the sound playing
    • enableSystemSounds

      public static void enableSystemSounds()
      Enables the playing of system sounds.
    • disableSystemSounds

      public static void disableSystemSounds()
      Disables the playing of system sounds.
    • systemSoundsEnabled

      public static boolean systemSoundsEnabled()
      Returns whether or not system sounds are enabled.
      Returns:
      true if system sounds are enabled, false otherwise
    • playSystemSound

      public static void playSystemSound​(java.lang.String soundFilename)
      Plays a specified system sound.

      Note that the application is not blocked.

      Parameters:
      soundFilename - the filename of the system sound to play
    • playSystemSound

      public static void playSystemSound​(java.lang.String soundFilename, MP3Player.EPlaying playing)
      Plays a specified system sound.
      Parameters:
      soundFilename - the filename of the system sound to play
      playing - specifies whether or not the application's execution should be blocked when playing the sound