com.annahid.libs.artenus.sound
SoundManager
Provides audio functionality for games. You can handle sound effects and music play-back easily
through static methods provided by this class.
public final class SoundManager
Constructor Summary
Modifier and Type | Constructor and Description |
---|---|
public | SoundManager() |
Method Summary
Modifier and Type | Method and Description |
---|---|
public static void | add(int... resourceIds) Adds sounds to the pool. |
public static float | getGeneralVolume() Gets the general volume of the sound manager. |
public static void | initContext(Context context) Initializes the class using the given application context. |
public static boolean | isContextInitialized() Determines whether the class has already been initialized. |
public static void | pauseMusic() Pauses play-back of the current background music. |
public static void | playMusic(String fileName) Plays a music file from the assets folder of the application. |
public static void | playSound(int resourceId) Plays a sound effect. |
public static void | playSound(int resourceId, float vol) Plays a sound effect with the given volume. |
public static void | resumeMusic() Resumes a previously paused background music, from where it was
paused. |
public static void | setGeneralVolume(float volume) Sets the general volume of the sound manager. |
public static void | setMusic(String fileName) Sets the current background music. |
public static void | setMusic(String fileName, float volume) Sets the current background music and sets the play-back volume to
the value specified. |
public static void | stopMusic() Stops play-back of the current background music and releases any
resources allocated for it. |
public static void | stopSound(int resourceId) Stops play-back of a currently playing sound. |
public static void | unloadAll() Unloads all music resources and clears the sound effect pool. |
Methods inherited from java.lang.Object
clone
, equals
, finalize
, getClass
, hashCode
, notify
, notifyAll
, toString
, wait
, wait
, wait
Method Detail
add | ||
---|---|---|
public static void add( int... resourceIds ) Adds sounds to the pool. You must add all your sound effects to the pool
before using them in the game. Parameters:
|
getGeneralVolume |
---|
public static float getGeneralVolume() Gets the general volume of the sound manager. Returns:
A number between 0 and 1. Number 0 means the sound is mute
and 1 is the loudest sound. |
initContext | ||
---|---|---|
public static void initContext( Context context ) Initializes the class using the given application context. Parameters:
|
isContextInitialized |
---|
public static boolean isContextInitialized() Determines whether the class has already been initialized. Returns:
true if initialized, or false otherwise |
pauseMusic |
---|
public static void pauseMusic() Pauses play-back of the current background music. The music will
remain at its current position until resumed. This method has no
effect it there is no background music or if the music has already
been paused. |
playMusic | ||
---|---|---|
public static void playMusic( String fileName ) Plays a music file from the assets folder of the application.
The music is played only once. Parameters:
|
playSound | ||
---|---|---|
public static void playSound( int resourceId ) Plays a sound effect. The sound should be already added to the pool using
add(int...) .Parameters:
|
playSound | ||||
---|---|---|---|---|
public static void playSound( int resourceId, float vol ) Plays a sound effect with the given volume. The sound should be already
added to the pool using Parameters:
|
resumeMusic |
---|
public static void resumeMusic() Resumes a previously paused background music, from where it was
paused. This method has no effect if there is no background music
or if the music is not paused. |
setGeneralVolume | ||
---|---|---|
public static void setGeneralVolume( float volume ) Sets the general volume of the sound manager. Parameters:
|
setMusic | ||
---|---|---|
public static void setMusic( String fileName ) Sets the current background music. The music will start playing
immediately in a loop after calling this function. Specifying
null for the file name will stop play-back and remove the
background music. Parameters:
|
setMusic | ||||
---|---|---|---|---|
public static void setMusic( String fileName, float volume ) Sets the current background music and sets the play-back volume to
the value specified. The music will start playing immediately in a
loop after calling this function. Specifying null for the
file name will stop play-back and remove the background music. Parameters:
|
stopMusic |
---|
public static void stopMusic() Stops play-back of the current background music and releases any
resources allocated for it. Resuming the music will have no effect
after it has been stopped. In order to restart play-back, you should
use playMusic or setMusic methods again. |
stopSound | ||
---|---|---|
public static void stopSound( int resourceId ) Stops play-back of a currently playing sound. Parameters:
|
unloadAll |
---|
public static void unloadAll() Unloads all music resources and clears the sound effect pool. After
calling this method, you cannot play any of the sound effects that
were added to the pool. |