// Sound volume
Int streamVolume;
// Define the SoundPool object private SoundPool soundPool;
// Define the private HashMap of the HASH table <Integer, Integer> soundPoolMap;
/*************************************** * ************************* Function: initSounds ();
* Parameters: null
* Returns: None.
* Description: Initialize the sound system.
* Notes: none.
**************************************** ***********************/
Public void initSounds () {// initialize the soundPool object. The first parameter is the number of sound streams that can be played simultaneously. The first parameter is the sound type, the third parameter is the sound quality soundPool = new SoundPool (100, AudioManager. STREAM_MUSIC, 100 );
// Initialize the HASH table soundPoolMap = new HashMap <Integer, Integer> ();
// Obtain the volume of the sound device and device. AudioManager mgr = (AudioManager) context. getSystemService (Context. AUDIO_SERVICE );
StreamVolume = mgr. getStreamVolume (AudioManager. STREAM_MUSIC );
}
/*************************************** * ************************* Function: loadSfx ();
* Parameters: null
* Returns: None.
* Description: loads audio resources.
* Notes: none.
**************************************** ***********************/
Public void loadSfx (int raw, int ID) {// load the sound effect in the resource to the specified ID (this is the ID when playing the video) soundPoolMap. put (ID, soundPool. load (context, raw, ID ));
}
/*************************************** * ************************* Function: play ();
* Parameters: sound: the ID of the sound to be played, loop: number of cycles
* Returns: None.
* Description: playback sound
* Notes: none.
**************************************** ***********************/
Public void play (int sound, int uLoop) {soundPool. play (soundPoolMap. get (sound), streamVolume, streamVolume, 1, uLoop, 1f );}