//Volume of Sound intStreamvolume; //define Soundpool object private Soundpool Soundpool; //define the hash table private Hashmap<integer, integer> Soundpoolmap; /*************************************************************** * Function:initsounds (); * Parameters:null * returns:none. * Description: Initialize sound system * Notes:none. ***************************************************************/ Public voidInitsounds () {//initializes the Soundpool object, the first parameter is how many sound streams are allowed to play simultaneously, the 2nd parameter is the sound type, and the third parameter is the quality of the sound Soundpool = new Soundpool (AUDIOMANAGER.STREAM_ MUSIC, 100); //Initialize hash Table Soundpoolmap = new Hashmap<integer, integer> (); //get sound device and device volume Audiomanager mgr = (audiomanager) context.getsystemservice (context.audio_service);Streamvolume=Mgr.getstreamvolume (Audiomanager.stream_music); }/*************************************************************** * FUNCTION:LOADSFX (); * Parameters:null * returns:none. * Description: Load Sound resources * Notes:none. ***************************************************************/ Public voidLOADSFX (intRawintID) {//load the sound from the resource into the specified ID (which corresponds to this ID when playing) soundpoolmap.put (ID, soundpool.load (context, raw, id));}/*************************************************************** * Function:play (); * Parameters:sound: The ID of the sound to play, loop: number of cycles * returns:none. * Description: Play sound * notes:none. ***************************************************************/ Public voidPlayintSoundintUloop) {Soundpool.play (Soundpoolmap.get (sound), Streamvolume, Streamvolume,1, Uloop, 1f); }