Package org.openpatch.scratch.internal
Class Sound
java.lang.Object
org.openpatch.scratch.internal.Sound
The Sound class represents a sound object in Scratch using Java's internal
audio classes.
The decoded audio of a file is loaded once and shared, but every sound object plays on a line of its own. Ten sprites that all added the same sound therefore sound ten times at once, while a single sprite still only plays its own sound once at a time.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangeVolume(double step) getName()doublebooleanstatic org.openpatch.scratch.internal.Sound.SamplesDecodes a sound file into memory, or returns it if that already happened.static SoundofNameOrPath(String name, String pathOrBuiltin) Creates a sound from either the name of a sound bundled with Scratch for Java or a path to a sound file.voidpause()voidplay()Plays the sound.voidsetVolume(double amp) voidstop()
-
Constructor Details
-
Sound
-
Sound
-
-
Method Details
-
ofNameOrPath
Creates a sound from either the name of a sound bundled with Scratch for Java or a path to a sound file.A string without a file extension is looked up in
BuiltinSounds, everything else is treated as a path, so existing code keeps working.- Parameters:
name- the name the sound should havepathOrBuiltin- a bundled sound name or a path to a sound file- Returns:
- the sound
-
loadSound
Decodes a sound file into memory, or returns it if that already happened.Only the samples are cached, not a playable line, so the same file can be played by any number of objects at the same time.
- Parameters:
path- the path to the sound file- Returns:
- the decoded audio
-
getName
-
play
public void play()Plays the sound. A single sound object plays one sound at a time, but other objects holding the same sound are unaffected and can play it alongside. -
pause
public void pause() -
stop
public void stop() -
isPlaying
public boolean isPlaying() -
setVolume
public void setVolume(double amp) -
changeVolume
public void changeVolume(double step) -
getVolume
public double getVolume()
-