Class SoundEngine
java.lang.Object
fr.r1r0r0.deltaengine.model.engines.SoundEngine
- All Implemented Interfaces:
Engine
,java.lang.Runnable
public final class SoundEngine extends java.lang.Object implements Engine
Sound Engine, allows to control all given sounds.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,javafx.scene.media.MediaPlayer>
sounds
-
Constructor Summary
Constructors Constructor Description SoundEngine()
Default constructor. -
Method Summary
Modifier and Type Method Description void
addSound(Sound sound)
Add a sound to the engine.javafx.scene.media.MediaPlayer
getMediaPlayer(java.lang.String name)
Gets associated music JavaFX Media Player, to have full customizationvoid
init()
Initialize the Engine.void
pause(java.lang.String name)
Pause a sound.void
play(java.lang.String name)
Play a sound.boolean
removeSound(java.lang.String name)
Remove a sound previously added from the engine.void
run()
void
setBalance(java.lang.String name, double balance)
Set balance to a specific sound.void
setLoop(java.lang.String name, boolean setLoop)
Allows looping or not specified music.void
setMute(java.lang.String name, boolean setMute)
Allows mute or unmute specified music.void
setSpeed(java.lang.String name, double speed)
Set speed to a specific sound.void
setVolume(java.lang.String name, double volume)
Set volume to a specific sound.void
stop(java.lang.String name)
Stop a sound.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
sounds
private final java.util.Map<java.lang.String,javafx.scene.media.MediaPlayer> sounds
-
-
Constructor Details
-
SoundEngine
SoundEngine()Default constructor.
-
-
Method Details
-
init
public void init()Description copied from interface:Engine
Initialize the Engine. -
run
public void run()- Specified by:
run
in interfacejava.lang.Runnable
-
addSound
Add a sound to the engine. Sound Name must be unique.- Parameters:
sound
- sound to add- Throws:
SoundAlreadyExistException
- exception thrown if sound name was already added previously
-
removeSound
public boolean removeSound(java.lang.String name)Remove a sound previously added from the engine.- Parameters:
name
- sound name to remove- Returns:
- true if removed, false otherwise (if sound doesn't exist)
-
play
Play a sound. Must be added before.- Parameters:
name
- sound name to play- Throws:
SoundDoesNotExistException
- if sound name is unknown for the engine- See Also:
to add a sound before playing it
-
pause
Pause a sound. Must be added before.- Parameters:
name
- sound name to pause- Throws:
SoundDoesNotExistException
- if sound name is unknown for the engine- See Also:
to add a sound before pause it
-
stop
Stop a sound. Must be added before.- Parameters:
name
- sound name to stop- Throws:
SoundDoesNotExistException
- if sound name is unknown for the engine- See Also:
to add a sound before stopping it
-
setVolume
Set volume to a specific sound. Must be added before.- Parameters:
name
- sound name to update volumevolume
- new sound volume, must be in range [0.0, 1.0]- Throws:
SoundDoesNotExistException
- if sound name is unknown for the enginejava.lang.IllegalArgumentException
- if volume value is outside authorized range- See Also:
to add a sound before updating its properties
-
setBalance
Set balance to a specific sound. Must be added before.- Parameters:
name
- sound name to update volumebalance
- new sound balance, must be in range [-1.0, 1.0]- Throws:
SoundDoesNotExistException
- if sound name is unknown for the enginejava.lang.IllegalArgumentException
- if volume balance is outside authorized range- See Also:
to add a sound before updating its properties
-
setSpeed
Set speed to a specific sound. Must be added before.- Parameters:
name
- sound name to update volumespeed
- new sound speed, must be in range [0.0, 8.0]- Throws:
SoundDoesNotExistException
- if sound name is unknown for the enginejava.lang.IllegalArgumentException
- if volume speed is outside authorized range- See Also:
to add a sound before updating its properties
-
setMute
Allows mute or unmute specified music. Must be added before.- Parameters:
name
- sound name to mute/unmutesetMute
- boolean: true to mute, false to unmute- Throws:
SoundDoesNotExistException
- if sound name is unknown for the engine- See Also:
to add a sound before updating its properties
-
setLoop
Allows looping or not specified music. Must be added before.- Parameters:
name
- sound name to loop (or not)setLoop
- boolean: true to loop, false to not loop- Throws:
SoundDoesNotExistException
- if sound name is unknown for the engine- See Also:
to add a sound before updating its properties
-
getMediaPlayer
public javafx.scene.media.MediaPlayer getMediaPlayer(java.lang.String name) throws SoundDoesNotExistExceptionGets associated music JavaFX Media Player, to have full customization- Parameters:
name
- sound name Media Player to get- Returns:
- MediaPlayer javafx object
- Throws:
SoundDoesNotExistException
- if sound name is unknown for the engine- See Also:
to add a sound before trying to get its player
-