Package org.sm.smtools.util
Class MP3Player
java.lang.Object
java.lang.Thread
org.sm.smtools.util.MP3Player
- All Implemented Interfaces:
Runnable
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
Modifier and TypeClassDescriptionstatic enum
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
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorDescriptionMP3Player
(InputStream soundInputStream) Constructs anMP3Player
object based on a specifiedInputStream
.Constructs anMP3Player
object based on a specified filename. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the player.static void
Disables the playing of system sounds.static void
Enables the playing of system sounds.void
play
(MP3Player.EPlaying playing) Starts playing a loaded sound file or stream.static void
playSystemSound
(String soundFilename) Plays a specified system sound.static void
playSystemSound
(String soundFilename, MP3Player.EPlaying playing) Plays a specified system sound.void
run()
TheThread
's run() method.static boolean
Returns whether or not system sounds are enabled.Methods inherited from class java.lang.Thread
activeCount, 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
-
Constructor Details
-
MP3Player
Constructs anMP3Player
object based on a specified filename.- Parameters:
soundFilename
- the name of the file containing the MP3 sound- Throws:
FileNotFoundException
- if the specified file could not be found or loadedSoundPlayingException
- if something went wrong during playing
-
MP3Player
Constructs anMP3Player
object based on a specifiedInputStream
.- Parameters:
soundInputStream
- theInputStream
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()TheThread
's run() method. -
play
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
Plays a specified system sound.Note that the application is not blocked.
- Parameters:
soundFilename
- the filename of the system sound to play
-
playSystemSound
Plays a specified system sound.- Parameters:
soundFilename
- the filename of the system sound to playplaying
- specifies whether or not the application's execution should be blocked when playing the sound
-