"Project Instance" Android development game Audio code example

Source: Internet
Author: User

//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); }         

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.