Artenus 2D Framework
Artenus Reference
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 TypeConstructor and Description
public SoundManager()

Method Summary

Modifier and TypeMethod and Description
public static voidadd(int... resourceIds)
Adds sounds to the pool.
public static floatgetGeneralVolume()
Gets the general volume of the sound manager.
public static voidinitContext(Context context)
Initializes the class using the given application context.
public static booleanisContextInitialized()
Determines whether the class has already been initialized.
public static voidpauseMusic()
Pauses play-back of the current background music.
public static voidplayMusic(String fileName)
Plays a music file from the assets folder of the application.
public static voidplaySound(int resourceId)
Plays a sound effect.
public static voidplaySound(int resourceId, float vol)
Plays a sound effect with the given volume.
public static voidresumeMusic()
Resumes a previously paused background music, from where it was paused.
public static voidsetGeneralVolume(float volume)
Sets the general volume of the sound manager.
public static voidsetMusic(String fileName)
Sets the current background music.
public static voidsetMusic(String fileName, float volume)
Sets the current background music and sets the play-back volume to the value specified.
public static voidstopMusic()
Stops play-back of the current background music and releases any resources allocated for it.
public static voidstopSound(int resourceId)
Stops play-back of a currently playing sound.
public static voidunloadAll()
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

Constructor Detail

SoundManager
public  SoundManager()

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:
resourceIdsraw resource identifiers
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:
contextThe application context
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:
fileNameThe file name for the music file
playSound
public static void playSound(
    int resourceId
)
Plays a sound effect. The sound should be already added to the pool using add(int...).
Parameters:
resourceIdThe raw resource identifier for the sound
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:
resourceIdThe raw resource identifier for the sound
volThe volume to play the sound. This volume is relative to the normal play-back of the sound with the current system volume for media. This value should be specified as a number between 0 and 1.
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:
volumeThe new volume which is a number between 0 and 1
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:
fileNameThe file name for the music file. This name should correspond to a file in the assets folder of the application.
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:
fileNameThe file name for the music file
volumePlay-back volume
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:
resourceIdThe raw resource identifier for the sound
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.