Package COM. llkan. setup; import Java. util. hashmap; import Java. util. map; import Java. util. random; import COM. llkan. r; import android. content. context; import android. media. audiomanager; import android. media. mediaplayer; import android. media. soundpool;/*** sound control class * @ author WYF **/public class soundplayer {Private Static mediaplayer music; Private Static soundpool; Private Static Boolean musicst = True; // music switch Private Static Boolean soundst = true; // sound switch Private Static Context context; Private Static final int [] musicid = {R. raw. BG, R. raw. bg1, R. raw. bg2, R. raw. bg3}; Private Static Map <integer, integer> soundmap; // ing relationship between the Audio Resource ID and the loaded audio source ID/*** Initialization Method * @ Param C */public static void Init (context c) {context = C; initmusic (); initsound () ;}// initialize the audio player Private Static void initsound () {soundpool = New soundpool (10, audiomanager. stream_music, 100); soundmap = new hashmap <integer, integer> (); soundmap. put (R. raw. itemboom, soundpool. load (context, R. raw. itemboom, 1); soundmap. put (R. raw. sel, soundpool. load (context, R. raw. sel, 1);} // initialize the music player Private Static void initmusic () {int r = new random (). nextint (musicid. length); music = mediaplayer. create (context, musicid [R]); music. setlooping (true );} /*** Play sound ** @ Param resid sound resource ID */public static void playsound (INT resid) {If (soundst = false) return; integer soundid = soundmap. get (resid); If (soundid! = NULL) soundpool. play (soundid, 1, 1, 1, 0, 1);}/*** pause music */public static void pausemusic () {If (music. isplaying () music. pause ();}/*** play music */public static void startmusic () {If (musicst) music. start ();}/*** switch a music and play it */public static void changeandplaymusic () {If (music! = NULL) music. release (); initmusic (); startmusic ();}/*** obtain the music switch status * @ return */public static Boolean ismusicst () {return musicst ;} /*** set the music switch ** @ Param musicst */public static void setmusicst (Boolean musicst) {soundplayer. musicst = musicst; If (musicst) music. start (); else music. stop ();}/*** obtain the sound switch status * @ return */public static Boolean issoundst () {return soundst ;} /*** set the sound switch ** @ Param soundst */public static void setsoundst (Boolean soundst) {soundplayer. soundst = soundst;}/*** sounds 'status' */public static void boom () {playsound (R. raw. itemboom );}}