The volume of sound effects
int streamvolume;
Define Soundpool object Private Soundpool Soundpool;
Define hash Table Private Hashmap<integer, integer> Soundpoolmap;
/*************************************************************** * Function:initsounds ();
* Parameters:null
* Returns:none.
* Description: Initialize sound system
* Notes:none.
***************************************************************/
The public void Initsounds () {///initializes the Soundpool object, the first parameter is how many sound streams are allowed to play at the same time, the 2nd argument is the sound type, and the third parameter is the quality of the sound Soundpool = new Soundpool (100, Audiomanager.stream_music, 100);
Initialize hash Table Soundpoolmap = new Hashmap<integer, integer> ();
Obtain sound equipment and device volume Audiomanager mgr = (audiomanager) context.getsystemservice (Context.audio_service);
Streamvolume = Mgr.getstreamvolume (Audiomanager.stream_music);
}
/*************************************************************** * FUNCTION:LOADSFX ();
* Parameters:null
* Returns:none.
* Description: Loading sound resources
* Notes:none.
***************************************************************/
public void Loadsfx (int raw, int ID) {//load the sound effects in the resource to the specified ID (play the same as the ID when playing) soundpoolmap.put (ID, soundpool.load ( Context, raw, ID));
}
/*************************************************************** * Function:play ();
* Parameters:sound: ID of the sound effect to play, loop: number of cycles
* Returns:none.
* Description: Play sound
* Notes:none.
***************************************************************/
public void Play (int sound, int uloop) {Soundpool.play (Soundpoolmap.get (sound), Streamvolume, Streamvolume, 1, Uloop, 1f) ; }